Exclude custom taxonomy tag from loop

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.

Read More

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

thank you

Related posts

Leave a Reply

1 comment

  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.

    <?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.