Make use of the WP_Query
class, namely the tax_query
and fields
parameters. Get the count from the $found_posts
property. Please note, this is exemplary code.
$query = new WP_Query( [
'post_type' => 'games',
'tax_query' = [
'relation' => 'AND',
[
'taxonomy' => 'game_status',
'field' => 'slug',
'terms' => [ 'beaten' ],
],
[
'taxonomy' => 'console',
'field' => 'slug',
'terms' => [ 'switch' ],
]
],
'fields' => 'ids',
] );
$count = $query->found_posts;