如何使用WordPress显示与特定分类法相关的自定义帖子类型


How to display custom post types related to a specific taxonomy using WordPress

我正试图在WP中显示特定分类法的所有自定义帖子类型。

这是代码:

<?php
$args = array(
    'post_type' => 'team',
    'orderby'   => 'rand',
    'posts_per_page' => -1
);
$trit = new WP_Query($args);
while ($trit->have_posts()) : $trit->the_post();
    $post_id = get_the_ID();//POST ID
    $terms = get_the_terms($post->ID, 'tax_members' );
    ...
endwhile;

上面的脚本显示所有分类单元的所有成员(tax_members)。我的目标是只显示特定类别的成员。。。例如:玩家

我如何调用中的分类播放器

$terms = get_the_terms($post->ID, 'tax_members' );
<?php
            $queryArr = array(
            'post_type'        => 'team',
            'orderby'          => 'rand',
            'post_status'      => 'publish',
            'posts_per_page'   => -1,
            'tax_query' => array(
                        array(
                                'taxonomy' => 'tax_members',
                                'field'    => 'slug',
                                'terms'    => 'players',
                                'operator' => 'IN'
                            ),
                        ),
            );
            $trit = get_posts( $queryArr );
?>

试试这个

$args = array(
    'post_type' => 'team',
    'orderby'   => 'rand',
    'posts_per_page' => -1,
    'tax_query' => array(
        array(
            'taxonomy' => 'tax_members',
            'terms'    => array('players'),
            )
        ) 
    );