下面的查询总是返回最新的“新闻”帖子,而不是分类法为“sotm”的最新“新闻”帖子。我已经验证了自定义分类法的详细信息,名称是“Postat”,附加到帖子类型“news”,并且有一个术语“sotm”应用于我要显示的帖子。有人能指出可能的错误吗?
<?php
$sotmArticle_query = new WP_Query(array(
\'post_type\' => \'news\',
\'postCat\' => \'sotm\',
\'orderby\' => \'date\',
\'order\' => \'DESC\',
\'posts_per_page\' => 1
));
if($sotmArticle_query->have_posts()){
while($sotmArticle_query->have_posts()){ $sotmArticle_query->the_post();
?>
最合适的回答,由SO网友:anu 整理而成
尝试以下操作:
$sotmArticle_query = new WP_Query(
array(
\'post_type\' => \'news\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'postCat\',
\'field\' => \'slug\',
\'terms\' => \'sotm\'
)
),
\'orderby\' => \'date\',
\'order\' => \'DESC\',
\'posts_per_page\' => 1
)
);
if($sotmArticle_query->have_posts()){
while($sotmArticle_query->have_posts()){ $sotmArticle_query->the_post();
?>