Act DEV
Act DEV

Reputation: 129

Get Category list related to current page in wordpress

i need to display the category list related to the current page (based on selected category in admin.) in wordpress site. i tried with get_the_category($post_id). But it's not working. Thanks.

Upvotes: 1

Views: 496

Answers (1)

awats
awats

Reputation: 447

You can try get_the_terms() instead. It should return an array of cats. Wordpress considers categories a taxonomy, so specifying 'category' as the taxonomy type should do the trick.Hope this helps.

$array_of_cats = get_the_terms( $post->ID, 'category' );
  foreach($array_of_cats as $key=> $value){
  //output as a list...
  }

Function reference here.

Upvotes: 1

Related Questions