Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.