我试图将自定义分类法中的帖子显示到索引页面,但是当我查询结果时,也发现了最近添加的与分类法无关的帖子。
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 4,
'tax_query' => array(
'taxonomy' => 'city',
'field' => 'id',
'terms__in' => 227,
)
);
$arr_posts = new WP_Query($args);
我还可以选择显示最近的帖子,所以我想知道这是否是导致问题的原因。
如果是这样,我想知道从定制分类法到首页显示最新帖子的正确方法。
答案 0 :(得分:2)
您的tax_query
不正确。请检查以下查询。
$args = array (
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 4,
'tax_query' => array(
array(
'taxonomy' => 'city',
'field' => 'term_id',
'terms' => array( 227 ),
)
),
);
$arr_posts = new WP_Query($args);