[wp-trac] [WordPress Trac] #30273: WP_Query with admin_bar_menu resets $post
WordPress Trac
noreply at wordpress.org
Thu Nov 6 12:32:59 UTC 2014
#30273: WP_Query with admin_bar_menu resets $post
----------------------------+-----------------------------
Reporter: jag1989 | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 4.0
Severity: normal | Keywords:
Focuses: administration |
----------------------------+-----------------------------
I've been creating a new plugin based that adds some pages to the admin
menu using the admin_bar_menu action. When using this action with a new
WP_Query the global $post is being reset.
I've been able to work around this for now by temp setting and resetting
the $post variable.
This certainly seems like a bug, as I see no reason to not make a new
WP_Query in the admin bar.
{{{
global $post;
$temp_p = $post;
$args = array(
'post_type' => 'page',
'post_status' => array(
'publish', 'pending', 'draft', 'auto-
draft', 'future', 'private', 'inherit'
),
'posts_per_page' => -1,
);
$listpages = new WP_Query( $args );
if ( $listpages->have_posts() ) :
$args = array(
'id' => 'qn_pages',
'title' => 'Jump to Page',
'meta' => array(
'class' => 'wp-qn-container'
)
);
$wp_admin_bar->add_node( $args );
while ( $listpages->have_posts() ) :
$listpages->the_post();
$args = array(
'id' => get_the_ID(),
'title' => get_the_title(),
'href' => get_edit_post_link(),
'parent' => 'qn_pages'
);
$wp_admin_bar->add_node( $args );
endwhile;
endif;
wp_reset_postdata();
$post = $temp_p;
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/30273>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list