0

I'm trying to get all posts in a custom plugin loop that DO NOT share the same tag as the current one.

I'm trying:

$events = tribe_get_events([
    'start_date'     => 'now',
    'eventDisplay'   => 'list',
    'posts_per_page' => 3,
    'tag'            => $current_tag // <-- Trying to do the exact opposite of this
]);

I'm using https://theeventscalendar.com/ 's plugin. But under the hood, that just uses the normal WP args setup.

Is there a way to invert the tag selection to get posts that DO NOT have that tag?

1 Answer 1

1

I found an answer to my own question:

If I use the tax_query arg then I could specify 'operator' => 'NOT IN' like so:

$events = tribe_get_events([
    'tax_query' => array(
        array(
            'taxonomy' => 'post_tag',
            'field'    => 'name',
            'terms'    => $current_tag,
            'operator'  => 'NOT IN' // HERE
        )
        ),
    'start_date'     => 'now',
    'eventDisplay'   => 'list',
    'posts_per_page' => 3,
]);
1

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.