Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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.

<?php
$args = array(
    'cat' => 84,
    'posts_per_page' => 3,
    'offset' => 0,
    'tax_query' => array(
        'relation' => 'NOT IN',
        array(
            '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
endwhile;

// Reset Post Data
wp_reset_postdata();
?>

Edit: I added the usage.

share|improve this answer
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 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
add comment

Your Answer

 
discard

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.