Support » Fixing WordPress » query_posts and tags in 3.2.1

  • Hi

    I’m working on my site on my local server, and I’ve just upgraded to 3.2.1. Everything working fine except the posts on my home page, which are called with a query_string using combination of cat and tag – it seems the tag is no longer valid. This is the code:

    <?php $temp_query = $wp_query; ?>
    <?php query_posts('cat=106&tag=feat+feat'); ?>

    Worked fine with my previous install, but now no posts are being pulled into the page.

    If I remove ‘&tag=feat+feat’, it shows all posts in the 106 category. How do I restore it so that it only shows posts in that category AND are tagged ‘feat’? I’m stumped.

    Thanks a lot.

Viewing 7 replies - 1 through 7 (of 7 total)
  • I always do this – I end up replying to myself until it’s solved…

    So I realise now it’s probably because an earlier temp_query excludes that 106 category – so there’s now a conflict (for some reason). Full code (html stripped out):

    <!-- FEATURES COLUMN -->
    <?php $temp_query = $wp_query; ?>
    <?php query_posts('cat=-106&tag=feat+feat'); ?>
    <?php while (have_posts()) : the_post();?>
    <?php endwhile; ?>
    <!-- RIGHT COLUMN -->
    <?php $temp_query = $wp_query; ?>
    <?php query_posts('cat=106&tag=feat+feat'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php endif; ?>
    <?php endwhile; ?>
    <!-- END RIGHT COLUMN -->

    So the features column contains everything except posts in the ‘diary’ category, which is all served up in the right column.

    So the NEW question is: how do I write this so that the two queries don’t contradict one another? I’m guessing there’s a more elegant way to do this…

    Thanks again

    Do you need to reset the query between the two query calls?

    I think so, yes – how do I do that, do you know?

    <?php wp_reset_query(); ?>
    <?php $wp_query = $temp_query; ?>

    works. Also, removing temp_query from the first query_posts makes no difference, either. I’m a bit confused. I probably haven’t grasped how this works (or I’ve forgotten)

    Try using

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

    at the top and

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

    at the bottom.

    Thanks, but no dice. Exactly the same problem.

    The odd thing is that if I take ‘tag=feat+feat’ out from the second query, all the posts in that category appear. So it can’t be a case of the first query conflicting with the second. If I take out the cat=106, then all posts tagged ‘feat’ appear. It’s something to do with the combination of the two…


    <?php query_posts('cat=106&tag=feat'); ?>

    Or any combination of categories and tags where there is at least one with both, just doesn’t work at all.

    Does anyone else use this query? Can anyone else repeat this problem?

    If so, does the Codex need updating and an alternative put forward?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘query_posts and tags in 3.2.1’ is closed to new replies.