[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
Sun Oct 25 02:42:02 UTC 2020


#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:  needs-unit-tests good-first-bug      |     Focuses:  rest-api
  has-patch needs-testing                        |
-------------------------------------------------+-------------------------

Comment (by TimothyBlynJacobs):

 Hi @manzoorwanijk, sorry for such the long delay in getting back to you.

 This should be able to be simplified by calling `wp_reset_postdata` at the
 end of `prepare_item_for_response` since the main query will take care of
 backing up the post global.

 This will also need unit tests.

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


More information about the wp-trac mailing list