The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

query_posts and tags in 3.2.1 (8 posts)

  1. heriz
    Posted 5 years ago #


    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.

  2. heriz
    Posted 5 years ago #

    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

  3. rebelit
    Posted 5 years ago #

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

  4. heriz
    Posted 5 years ago #

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

  5. heriz
    Posted 5 years ago #

    <?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)

  6. Curtiss Grymala
    Posted 5 years ago #

    Try using

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

    at the top and

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

    at the bottom.

  7. heriz
    Posted 5 years ago #

    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...

  8. heriz
    Posted 5 years ago #


    <?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?

Topic Closed

This topic has been closed to new replies.

About this Topic