It doesn’t make any sense querying with get_terms
when:
genre="action"
AND
quality = 'HD'
The reason is: The only term that has taxonomy genre
equals to action
, is action
. And the only term that has taxonomy quality
equals to HD
, is HD
. If you constrain them with AND
, then basically you have nothing. Since there’s no term that satisfies both.
However, you can get movie
custom posts that satisfies that criteria. Which means, you need movies with action genre and HD quality.
If that is the case, then you may use the tax_query
argument in WP_Query
:
$args = array(
'post_type' => 'movie',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'genre',
'field' => 'slug',
'terms' => 'action',
),
array(
'taxonomy' => 'quality',
'field' => 'slug',
'terms' => 'HD',
),
)
);
echo '<h1>Movies with action genre and HD quality:</h1>';
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
echo '<ul>';
while ( $query->have_posts() ) {
$query->the_post();
echo '<li>';
the_title();
echo '</li>';
}
echo '</ul>';
} else {
echo '<h2>Nothing is found</h2>';
}