I have a page with the slug blog. Mysite.com/blog correctly renders from the template file page-blog.php. However, it does not execute footer code from my theme that's conditioned on is_page('blog'), nor does it have an "Edit Page" link in the Admin bar.

I also have a custom post type called blog, but this page doesn't execute code for is_post_type_archive('blog') either. In the admin bar, there is no "Edit Category" link or "Edit [Anything else]".

This is the info the WP Debug plugin gives me when I load the page:


Query String:

Matched Rewrite Rule:

Matched Rewrite Query:

What could be the problem?

  • First: Please go to your open answers and start marking solved Qs or comment on the answers. With 53% accept rate most people won't answer your Qs anymore. Second: var_dump($GLOBALS['wp_query']). – kaiser Aug 23 '11 at 17:06
  • 1
    Does your template file use query_posts without wp_reset_query? – Chris_O Aug 23 '11 at 18:31
  • It does use a secondary loop, and that is the cause of the problem—however, neither wp_reset_query() nor wp_reset_postdata() solve it. After the query and reset(s), var_dump($GLOBALS['wp_query']) still show the last post of the secondary loop. – supertrue Aug 24 '11 at 21:46

The problem was due to a secondary loop in the page—before this loop, the page knows it's a page; but after the loop (and in the footer, where the Admin Bar and my code would be rendered), the page thought it was the last post of the secondary loop.

Neither wp_reset_query() nor wp_reset_postdata() worked; I am guessing this has to do with the fact that I use $wp_query as the name of the secondary loop (so that I could use the loop.php template file to display the posts). Here's the code that worked:

$temp_query = clone $wp_query; 

$wp_query = new WP_Query( 'post_type=publication&posts_per_page=5' );

get_template_part( 'loop' );
/* get_template_part( 'loop' ) only seems to work if the query is in $wp_query */

$wp_query = clone $temp_query; ?>

Here's the link in the codex that the clone $wp_query technique comes from: http://codex.wordpress.org/The_Loop#Multiple_Loops_Example_2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.