Forums

A loop with a CATEGORY and a TAG (8 posts)

  1. borbs
    Member
    Posted 4 years ago #

    Hi!

    I want to create page that shows, on a loop, articles that belong to a category AND to a tag. For exemple, show all the articles that belong to the MOVIES category and are marked as DRAMA.

    How can I do that?

  2. MichaelH
    Volunteer
    Posted 4 years ago #

    Look at the Combining Parameters in the Codex article Template_Tags/query_posts for some examples.

    [edit - oops that example doesn't have what you need so will keep looking]

  3. borbs
    Member
    Posted 4 years ago #

    Yeah, I noticed that. I even tried this query
    <?php query_posts('cat=3&tag=13'); ?>
    But it shows only the posts that belong to the category. I also tried only the "tag=13" query, and it shows nothing.

    If anyone could help me... :)

  4. MichaelH
    Volunteer
    Posted 4 years ago #

    Try this

    <?php
    query_posts('tag=drama');
    if (have_posts()) : ?>
    <?php while (have_posts()) : the_post();
    if (in_category('3')) {
    ?>
    /*
    whatever you're displaying for your post here
    */
    <?php } ?>
    <?php endwhile; ?>
  5. borbs
    Member
    Posted 4 years ago #

    It gives me an error -- about an unexpected $end (the "}", in this case). I tried this query below (for multiple loops) and it keeps showing nothing... If I delete the "cat" or "tag" info, it works. But both of them not... =/

    <?php $my_query = new WP_Query(array('tag'=>drama,'cat'=>3,'showposts'=>4,'orderby'=>id,'order'=>DESC));
    
         while ($my_query->have_posts()) : $my_query->the_post();?>
  6. aradams
    Member
    Posted 4 years ago #

    See this post:

    http://wordpress.org/support/topic/146199?replies=7

    Your example <?php query_posts('cat=3&tag=13'); ?> won't work--it seems like right now you can't use BOTH cat= and tag= in query_posts.

    BTW the code MichaelH posted above breaks for me too.

  7. the_dead_one
    Member
    Posted 4 years ago #

    If your interested... I did write a plugin that supports a category and tag archive -- See http://wordpress.org/extend/plugins/tdo-tag-fixes/

    I wrote it as an example how to support category and tag intersection.

  8. PhaZZed
    Member
    Posted 3 years ago #

    MichaelH's theory does work, you're clearly just missing a close for the IF condition..

    Thanks MichaelH - Took me 2 days to find this and it's finally working!

Topic Closed

This topic has been closed to new replies.

About this Topic