[wp-trac] [WordPress Trac] #18408: Can't wp_reset_postdata after custom WP_Query in an admin edit page

WordPress Trac noreply at wordpress.org
Tue Nov 3 17:05:17 UTC 2020


#18408: Can't wp_reset_postdata after custom WP_Query in an admin edit page
-----------------------------------------------+---------------------------
 Reporter:  ericlewis                          |       Owner:  ericlewis
     Type:  defect (bug)                       |      Status:  reopened
 Priority:  normal                             |   Milestone:  Future
                                               |  Release
Component:  Query                              |     Version:  4.7.2
 Severity:  normal                             |  Resolution:
 Keywords:  needs-testing ongoing needs-patch  |     Focuses:
-----------------------------------------------+---------------------------

Comment (by Howdy_McGee):

 In the admin panel the `global $wp_query` is technically still available
 for use. We could simply store the `global $post` during the `loop_start`
 hook when specific flags are set ( `is_admin()`? ):


 {{{
 add_action( 'loop_start', function() {

         if( ! is_admin() ) {
                 return;
         }

         global $post,
         $wp_query;

         $wp_query->post = $post;

 } );
 }}}

 The above is a simple example but it seems like the `global $wp_query` is
 kept empty in most if not all admin panel requests. This would then allow
 the use of secondary WP_Querys and `wp_reset_postdata()`.

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


More information about the wp-trac mailing list