My WP_query in the header menu fails to pull any posts on tag and category pages only. Error occurs even with the Loop removed from those template pages.

The menu in the header lists the parents. Then for each parent, it then queries for their child posts and image. Interestingly, (ALL) the posts appear when 'post_parent' condition is removed from $group_nav.

I'm relatively new to php so any help is much appreciated. This issue has been giving me grief for the last 3 days!

drop-down menu canbe viewed here: http://d1079691-5522.myweb.westnethosting.com.au/wsp-ie.com.au/?industry=construction

and mis-behaving here: http://d1079691-5522.myweb.westnethosting.com.au/wsp-ie.com.au/?tag=synthetic-leather

Coding in header.php

<?php $temp_query = clone $wp_query; ?>

<?php $group_nav_ids = array(916,917,918,919,920,921); //custom post type parent ids
foreach ($group_nav_ids as $group_nav_id): ?>              

*do stuff       

<?php $group_nav = new WP_Query(array( //get children posts
'post_type'         => 'pgroup',
'post_parent'       => $group_nav_id,                               
'order'             => 'ASC',
'orderby'           => 'menu_order',
'posts_per_page'    => -1

if ($group_nav->have_posts()) : ?>       
<?php while ($group_nav->have_posts()) : $group_nav->the_post(); ?>

*do stuff

<?php endwhile; ?>
<?php endif; ?>
<?php endforeach; ?>

<?php wp_reset_query(); wp_reset_postdata(); rewind_posts(); ?>

<?php $wp_query = clone $temp_query; ?>
  • the first and last lines are completely pointless, they should be removed. also, you only need wp_reset_postdata() after a custom loop, wp_reset_query() and rewind_posts() can be removed.
    – Milo
    May 30, 2013 at 3:11
  • Hi Milo. Thanks for the tip. Code is tidier, however original issue remains.
    – user33445
    May 30, 2013 at 3:39

1 Answer 1


Just in case anyone happens to run into this same problem, my round-about solution for taxonomy template query conflict:

  1. clone the main query
  2. NULL the query
  3. define new WP_Query
  4. re-instate cloned query

Tested and working in header.php

global $wp_query; 
$temp_query = clone $wp_query;
global $post; 
$temp_post = clone $post;
$wp_query = NULL; 

$wp_query = new WP_Query( $args ); 

$wp_query = clone $temp_query; 
$post = clone $temp_post;
  • It makes no sense that this would work while a completely custom WP_Query would not. I assume your issue was elsewhere and this "accidentally" fixed it. I wouldn't recommend anyone handle queries this way, it's quite messy.
    – Milo
    May 30, 2013 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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