Tags, use both union and intersection at the same time

I have tags on posts and I want a display based on the following logic:
If it has the “biology” tag AND it has either the “female” or “male” tag.

biology AND (female OR male)

Read More

Here’s what I attempted but it didn’t work:
http://www.example.org/tag/biology+female,male

Obviously the above is ambiguous, is there a way to do what I’m needing?

Related posts

Leave a Reply

1 comment

  1. You can achieve this with a tax_query, though by default not via any sort of URL manipulation:

    $args = array(
        'post_type' => 'post',
        'tax_query' => array(
            'relation' => 'AND',
            array(
                'taxonomy' => 'post_tag',
                'field' => 'slug',
                'terms' => array( 'biology' )
            ),
            array(
                'taxonomy' => 'post_tag',
                'field' => 'slug',
                'terms' => array( 'male', 'female' ),
                'operator' => 'IN'
            )
        )
    );
    $query = new WP_Query( $args );
    

    If you wanted to do this via URL, you’d have to come up with some way to pass the terms so you could intercept and create the query.