WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

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.

share|improve this answer
+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 Feb 12 '12 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 Feb 12 '12 at 23:12
I added the usage in my post. – imHavoc Feb 12 '12 at 23:30
Also, start_wp() has been deprecated for some time now. It has been effectively replaced by the_post. – imHavoc Feb 12 '12 at 23:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.