我正在尝试在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' );
答案 0 :(得分:1)
$args = array(
'post_type' => 'team',
'orderby' => 'rand',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'tax_members',
'terms' => array('players'),
)
)
);
答案 1 :(得分:1)
<?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 );
?>
试试这个