[wp-trac] [WordPress Trac] #43502: `WP_REST_Posts_Controller::prepare_item_for_response()` doesn't reset postdata after calling setup_postdata()

WordPress Trac noreply at wordpress.org
Sat Aug 2 13:58:16 UTC 2025


#43502: `WP_REST_Posts_Controller::prepare_item_for_response()` doesn't reset
postdata after calling setup_postdata()
-------------------------------------------------+-------------------------
 Reporter:  gerbenvandijk                        |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  Future
                                                 |  Release
Component:  REST API                             |     Version:  4.9.4
 Severity:  normal                               |  Resolution:
 Keywords:  good-first-bug has-patch needs-      |     Focuses:  rest-api
  unit-tests                                     |
-------------------------------------------------+-------------------------

Comment (by sachinrajcp123):

 I’ve submitted a patch (43502.5.diff) that adds `wp_reset_postdata()`
 after `setup_postdata()` in the `prepare_item_for_response()` method of
 the `WP_REST_Posts_Controller` class.

 This ensures global post data is restored after rendering post data for
 the REST API. Kindly review the patch.

 Props sachinrajcp123

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/43502#comment:25>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list