monsaic123
monsaic123

Reputation: 251

How to use get_the_category() and display the categories in menu order?

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;
        }
    }

Upvotes: 0

Views: 1193

Answers (1)

Stender
Stender

Reputation: 2492

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.

Upvotes: 4

Related Questions