scottiescotsman scottiescotsman - 1 year ago 62
PHP Question

how to list custom post type 'movies' with a genre of 'horror'

I have been trying to list my custom type 'movies' with the custom taxonomy genre with a value of drama.
I have tried several solutions but as yet I have failed.


$args = array(
'post_type' => 'movies',
'tax_query' => array(
'taxonomy' => 'genre',
'field' => 'term_id',
'terms' => 'drama'

$drama = new WP_Query( $args );

if ( $drama->have_posts() ) : while ( $drama->have_posts() ) : $drama->the_post(); ?>

<h4><?php echo the_title(); ?></h4>

<?php endwhile; ?>

<?php else : echo '<p>NO CONTENT FOUND</p>'; ?>

<?php wp_reset_postdata(); ?>

<?php endif; ?>

Hope someone can shed some light on this matter.


Answer Source

The field parameter is wrong, in your case you need to set it to slug as drama is not a term_id

$args = array(
   'post_type'     => 'movies',
   'tax_query'     => array(
         'taxonomy'  => 'genre',
         'field'     => 'slug',
         'terms'     => 'drama'


Hope it works !

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download