• Resolved mrjonnywood

    (@jwoodcreative)


    I’m trying to exclude a tag from a query.

    I have this:

    <?php
    $events_query = new WP_Query(array(
        'post_type' => 'event',
        'tag__not_in'=> array(196),
        'orderby'=> 'eventstart',
        'order'=>'DESC'
    ));
    
    while ( $events_query->have_posts() ) : $events_query->the_post();
    ?>
    
    ...
    
    <?php
    wp_reset_postdata();
    endwhile;
    ?>

    But it’s not excluding the posts within tag ID 196. What am I doing wrong..?

    https://wordpress.org/plugins/event-organiser/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Stephen Harris

    (@stephenharris)

    tag__not_in is for post tags, you’ll need to use a tax_query with the ‘event-tag’ taxonomy to achieve this.

    Thread Starter mrjonnywood

    (@jwoodcreative)

    Wow, fast response! Thanks. Got it working with this:

    $events_query = new WP_Query(array(
        'post_type' => 'event',
        'tax_query' => array(
            array(
                'taxonomy' => 'event-tag',
                'field'    => 'term_id',
                'terms'    => '196',
                'operator' => 'NOT IN',
            ),
        ),
        'orderby'=> 'eventstart',
        'order'=>'DESC'
    ));
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘exclude tag from query’ is closed to new replies.