1

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)

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?

1 Answer 1

2

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.

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.