0

How to get the list of post categories I have this but it returns only one category and the entire list?

$categories = get_categories();
foreach($categories as $category) {
   echo 'term_id) . '">'  .$category->name .$category->term_id.  '';
}
 
2
  • Are you trying to get just the categories the current post is in?
    – WebElaine
    Aug 18, 2022 at 20:21
  • yes, i want to get category list
    – Jhon Fer
    Aug 18, 2022 at 21:31

1 Answer 1

0

To get categories assigned to the current post, use get_the_category().

get_categories() is designed to get a list of all categories on the site.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.