[wp-trac] [WordPress Trac] #39257: admin_notices bug when using wp_query

WordPress Trac noreply at wordpress.org
Sat Dec 17 02:42:31 UTC 2016


#39257: admin_notices bug when using wp_query
----------------------------+-----------------------------
 Reporter:  garethgillman   |       Owner:
     Type:  defect (bug)    |      Status:  closed
 Priority:  normal          |   Milestone:
Component:  Administration  |     Version:  4.7
 Severity:  normal          |  Resolution:  invalid
 Keywords:                  |     Focuses:  administration
----------------------------+-----------------------------
Changes (by johnbillion):

 * status:  new => closed
 * resolution:   => invalid
 * milestone:  Awaiting Review =>


Comment:

 Hi @garethgillman.

 The bug you're seeing is caused by the `$all_tasks_query->the_post()`
 line. This sets the global `$post` object to the current post in the loop.
 This same object is used to determine whether to populate the fields on
 the post editing screen. In addition, the call to `wp_reset_postdata()`
 has no effect because there is no post data to reset to.

 `the_post()` method is not intended to be used in the admin area in this
 way, and may have side effects on other screens too. You should refactor
 your code to use the results of the `WP_Query` call directly, instead of
 calling `$all_tasks_query->the_post()`.

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


More information about the wp-trac mailing list