WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to list categories, like wp_list_categories, but display also IDs? (4 posts)

  1. webipsum
    Member
    Posted 2 years ago #

    How to list categories (parents / children), like wp_list_categories, however, beyond the name, also display the ID?
    Tks.

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    Try it with this in your theme's functions.php :

    add_filter('list_cats', 'cats_with_id', 10, 2);
    function cats_with_id($category, $cat_list){
    if($cat_list)
      return $category . ' ' .$cat_list->term_id;
    else
      return $category;
    }
  3. webipsum
    Member
    Posted 2 years ago #

    keesiemeijer.
    It worked wonderfully.
    Thanks so much!

  4. keesiemeijer
    moderator
    Posted 2 years ago #

    No problem, glad you got it resolved. I changed the code a little bit, so it's only used on the front end of your website:

    if(!is_admin()){
    add_filter('list_cats', 'cats_with_id', 10, 2);
    }
    function cats_with_id($category, $cat_list = false){
    if($cat_list)
      return $category . ' ' .$cat_list->term_id;
    else
      return $category;
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.