Skip to content

Instantly share code, notes, and snippets.

@SErr0r
Created June 20, 2016 14:26
Show Gist options
  • Save SErr0r/624f8824728bc6ec0538403f878b1849 to your computer and use it in GitHub Desktop.
Save SErr0r/624f8824728bc6ec0538403f878b1849 to your computer and use it in GitHub Desktop.
Filter by Taxonomy with AND/OR Relation between multiple taxonomies
<?php
$args = array(
'post_type' => 'post',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'movie_genre',
'field' => 'slug',
'terms' => array( 'action', 'comedy' )
),
array(
'taxonomy' => 'actor',
'field' => 'id',
'terms' => array( 103, 115, 206 ),
'operator' => 'NOT IN'
)
)
);
$query = new WP_Query( $args );
?>
@SErr0r
Copy link
Author

SErr0r commented Jun 20, 2016

We shall even use 'operator' with values 'AND/OR/NOT/NOT IN' relation with in a taxonomy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment