如何列出类型为 'horror' 的自定义 post 类型 'movies'

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

我一直在尝试将我的自定义类型 'movies' 与具有戏剧价值的自定义分类流派一起列出。 我已经尝试了几种解决方案,但我都失败了。

<?php

$args = array(
'post_type'     => 'movies',
'tax_query'     => array(
    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; ?>

希望有人能对这件事有所了解。

史蒂文

field 参数错误,在你的情况下你需要将它设置为 slug 因为 drama 不是 term_id

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

);

希望有用!