I have the following code at the beginning of a loop:

<?php query_posts('showposts=3&cat=84'); ?>
<?php $posts = get_posts('category=84&numberposts=3&offset=0'); foreach ($posts as $post) : start_wp(); ?>

I have a custom taxonomy called "display," with a tag called "featured-slider." In this loop, I want to include everything from category 84, but I want to exclude everything with a "featured-slider" value in the "display" taxonomy.

How would I rewrite the two lines above (query_posts and get_posts) to correctly exclude the custom taxonomy?

thank you

1 Answer 1


I have rewritten the query_posts. As for get_posts you are better off using the WP_Query due to more control over the tax_query. Explained here.

$args = array(
    'cat' => 84,
    'posts_per_page' => 3,
    'offset' => 0,
    'tax_query' => array(
        'relation' => 'NOT IN',
            'taxonomy' => 'display',
            'field' => 'slug',
            'terms' => 'featured-slider'
$wpse42083_query = new WP_Query( $args );
while( $wpse42083_query->have_posts() ) : $wpse42083_query->the_post();
    // write post stuff in here

// Reset Post Data

Edit: I added the usage.

  • 2
    +1 for recommending WP_Query over either query_posts or get_posts. @sarah...please review this for the reason why: wordpress.stackexchange.com/questions/1753/…
    – tollmanz
    Commented Feb 12, 2012 at 20:46
  • Thanks for the help -- but I think I need more help to correctly write the WP_Query version that I would substitute for this line: <?php $posts = get_posts('category=84&numberposts=3&offset=0'); foreach ($posts as $post) : start_wp(); ?>
    – Sarah
    Commented Feb 12, 2012 at 23:12
  • I added the usage in my post.
    – Evan Yeung
    Commented Feb 12, 2012 at 23:30
  • Also, start_wp() has been deprecated for some time now. It has been effectively replaced by the_post.
    – Evan Yeung
    Commented Feb 12, 2012 at 23:31

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.