我创建了自定义帖子Electronics
。然后Electronics
有自定义分类appliences
。 appliances
包含home appliances
,kitchen appliances
等字词。现在home appliances
有一些帖子。
现在我想在home appliances
字词下显示帖子。我创建了一个页面taxonomy-appliances.php
。
---- Electronics (custom post)
|__ appliances (custom taxonimy)
|__home appliances
|__ posts
|
|__Kitchen appliances
|_posts
我如何在该页面中显示它?
这是我的代码:
<?php
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'appliances',
'field' => 'slug',
'terms' => 'home appliances',
)
)
);
$posts = new WP_Query($args);
if($posts->have_posts()){
while ($posts->have_posts()) : $posts->the_post();
echo get_the_title();
endwhile;
}
?>
但没有显示
答案 0 :(得分:0)
$args = array(
'post_type' => 'electronics', // your post type name
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'appliances', //your taxonomy name
'field' => 'slug',
'terms' => 'home-appliances',//here use the slug, check the slug of your term
)
)
);
答案 1 :(得分:0)
Try this,
$posts_array = get_posts(
array(
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'appliances',
'field' => 'slug',
'terms' => 'home-appliances',
)
)
)
);