使用特定术语执行 wordpress 循环

Do wordpress loop with a specific term

如何使用自定义 post 类型执行 wordpress post 循环,以仅显示来自自定义分类法的特定类别的 post?

$args = array(
    'post_type' => 'news',
    'taxonomy' => 'newscat',
    'field' => 'slug',
    'terms' => 'news',
    'posts_per_page' => 6,
);
$query = new WP_Query($args);
if($query -> have_posts()):while($query -> have_posts()):$query -> the_post();

你的论据不正确。

试试这个。

$args = array(
 'post_type' => 'news',
 'posts_per_page' => 6,
 'tax_query' => array(
    array(
     'taxonomy' => 'newscat',
     'field' => 'slug',
     'terms' => 'news'
  ),
 ),
);
$query = new WP_Query($args);
if($query -> have_posts()):while($query -> have_posts()):$query -> the_post();