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