I'm using the below code to show the categories of the current post (excluding cat id 14). Issue is they're not in the order I want. I need them to display in menu order.. Is this possible?
$categories = get_the_category();
foreach($categories as $category) {
$output = $category->cat_name;
if($category->cat_ID !== 14){
echo $output;
}
}
CodePudding user response:
After discussion in comments :
get_the_category()
doesn't accept orderby clauses, so use wp_get_post_terms()
instead.
Use it like this
$terms = wp_get_post_terms( get_the_id(), 'category', array( 'orderby' => 'term_order' , 'exclude' => array(14)));
This way the term with ID 14 is excluded as well.