问题描述
我没有得到自定义分类法 (fabric_building_types) 的帖子。我正在获取 cat_id 和 cat-> 名称,但不能得到帖子。
$args = array(
'type' => 'post',
'child_of' => 0,
'parent' => '',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 1,
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'number' => '',
'taxonomy' => 'fabric_building_types',
'pad_counts' => false
);
$categories = get_categories( $args );
foreach ( $categories as $cat ) {
// here's my code for getting the posts for custom post type
$posts_array = get_posts(
array( 'showposts' => -1,
'post_type' => 'fabric_building',
'tax_query' => array(
array(
'taxonomy' => 'fabric_building_types',
'field' => $cat->cat_ID,
'terms' => $cat->name,
)
)
)
);
print_r( $posts_array );
}
任何人都可以帮助我… 谢谢提前
最佳解决方案
您的税务查询不正确,field
应该是您要查询的字段:term_id
,name
或 slug
–
$posts_array = get_posts(
array(
'posts_per_page' => -1,
'post_type' => 'fabric_building',
'tax_query' => array(
array(
'taxonomy' => 'fabric_building_types',
'field' => 'term_id',
'terms' => $cat->term_id,
)
)
)
);
参考文献
注:本文内容整合自 Google/Baidu/Bing 辅助翻译的英文资料结果。如果您对结果不满意,可以加入我们改善翻译效果:薇晓朵技术论坛。