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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744961869a4603437.html
评论列表(0条)