I have a custom Post Type called Movies, and an associated Taxonomy called Genre. Now I need to list all CPT(s) which are in Genre of 'Comedy' in my own custom page (regardless of WP parmalink mechanism)

Following code only returns the custom post type moviesCPT:

$args = array( 'post_type' => 'moviesCPT', 'posts_per_page' => 10 );
$loop = new      WP_Query( $args ); 
while ( $loop->have_posts() ) :
 $loop->the_post(); the_title(); 
echo '<div class="entry-content">'; the_content();
echo '</div>'; 

Can you please let me know how to handle this?

1 Answer 1


Specify this when you make your query:

'genre' => 'comedy'

Where genre is the name of your taxonomy ( not the human readable version, but the internal slug ), and comedy is the slug of the term you want to filter by

Importantly, indent your query parameters, and put them each on their own line so that it's easy to read/type/change, a good editor will do this for you. You also need to do an if( $loop->have_posts() ) to check that you got posts and handle things if none were found, and a wp_reset_postdata call to clean up at the end ( otherwise any calls you make will show the last movie in the loop, rather than the current post/page )

You can use the tax_query parameter for more complex queries, the details are in the codex under the WP_Query documentation

  • I will start to love these taxonomies.
    – prosti
    Jan 13, 2017 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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