Opened 8 years ago
Closed 8 years ago
#39257 closed defect (bug) (invalid)
admin_notices bug when using wp_query
Reported by: | garethgillman | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.7 |
Component: | Administration | Keywords: | |
Focuses: | administration | Cc: |
Description
I have the following code: http://pastebin.com/3cshwQ8U
This causes: http://www.awesomescreenshot.com/image/1948334/30b6abe1dc1661bc045e218ff23403a0
It auto fills out the title, slug and content from the last post in the query, tested on 2 different cleans sites on 4.5 and 4.6
It leads me to believe that the global $query object is being interfered with by instantiating a new WP_Query class inside the admin_notices hook
Change History (2)
Note: See
TracTickets for help on using
tickets.
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 towp_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 theWP_Query
call directly, instead of calling$all_tasks_query->the_post()
.