• Resolved acornrevolution

    (@acornrevolution)


    I am using the following code on my front page for querying recent posts. I am excluding category 3, however this also excludes any posts that have several categories, one of which is category 3 (i.e. a post in category 15 and 3). How can I include these kinds of posts?

    <?php
        $recentPosts = new WP_Query();
        $recentPosts->query('showposts=5&cat=-3');
    ?>
    <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
        <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Don’t know if this is the best solution, but the obvious answer is to limit it to showing all the categories except category 3.

    e.g.

    <?php
        $recentPosts = new WP_Query();
        $recentPosts->query('showposts=5&cat=1,2,4,5');
    ?>

    Hi,

    Check with this plugin:

    http://wordpress.org/extend/plugins/query-posts/

    Thanks,

    Shane G.

    Thread Starter acornrevolution

    (@acornrevolution)

    danoprey, that worked! I wasn’t going to do it at first, since I have 9 categories, but they are fixed, so I wont have to worry about adding more. Thanks!

    Shane G., this wasn’t for the sidebar, but thanks!

    Lets say I have a category with ID=3 and it’s many more sub-categories.
    But I want to display posts only from catID=3 not it’s sub-cat…
    How can we modify this code…?

    $recentPosts->query(‘showposts=5&cat=1,2,4,5’);

    Nimit

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Query Posts Question’ is closed to new replies.