admin管理员组文章数量:1406921
I have three parent categories with child cats belonging to each, Project Type, Sector and Country. Currently the code I have displays all categories by default when selected.
$categories_in_text = '';
foreach ($taxonomies as $key => $taxonomy) {
$post_terms = get_the_terms($post_id, $taxonomy);
if(is_array($post_terms) && !empty($post_terms)){
foreach($post_terms as $term){
if(in_array($term->taxonomy."||".$term->term_id, $post_categories)){
$show = true;
}
$categories_in_text .= $term->name.' ';
}
}
}
$post_title .= '<div class="project-cat"> '.$categories_in_text.'</div>';
Ideally I only want to display the children of Country and Sector and hoping that doing this by ID would be the way to go. The order is important as the Country must come first followed by the Sector.
Is there some form of array that I can use so WP only displays the categories in the array? Project Type child cats are used by the user so will be selected, just don't want it displayed in this code.
本文标签: taxonomyDisplay specific categories by ID
版权声明:本文标题:taxonomy - Display specific categories by ID 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744961869a2634705.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论