On a project I’m working on the client wanted to show only posts from a custom post type that belonged to a specific custom taxonomy. I did a search on Google and didn’t really find any complete solution.
$post_type = 'project'; $taxonomy = 'skill'; $taxonomy_term_id = 5; $projects = new WP_Query([ 'post_type' => $post_type, 'numberposts' => - 1, 'posts_per_page' => - 1, 'tax_query' => [ [ 'taxonomy' => 'skill', 'field' => 'id', 'terms' => $taxonomy_term_id , 'include_children' => false ] ] ]);
This will get all posts of custom post type ‘project’ that has a custom taxonomy ‘skill’ and where that skill contains the skill term with id 5.
There is more on interacting with WP Query in the documentation