[英]get_posts() instead of query_posts() for a custom post linked with a custom taxonomy term
[英]Showing posts of a term under a custom taxonomy of a custom post
我创建了一个自定义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;
}
?>
但是什么都没有显示
$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
)
)
);
Try this,
$posts_array = get_posts(
array(
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'appliances',
'field' => 'slug',
'terms' => 'home-appliances',
)
)
)
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.