WordPress.org

Ready to get started?Download WordPress

Forums

get cat id with wp_list_categories (3 posts)

  1. oblax
    Member
    Posted 1 year ago #

    Hi,

    I need to also get each category id from wp_list_categories function. Is it possible?

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    the id is part of the markup:
    http://codex.wordpress.org/Template_Tags/wp_list_categories#Markup_and_Styling_of_Category_Lists

    but obviously not directly accessible;

    if you explain why and what you need the id for, someone might be able to suggest more details.

    or use get_categories() instead
    http://codex.wordpress.org/Function_Reference/get_categories

  3. prionkor
    Member
    Posted 1 year ago #

    As alchymyth said, use get_categories()

    <?php
    $args=array(
      'orderby' => 'name',
      'order' => 'ASC'
      );
    
    $categories = get_categories($args);
    
    //now you have all categories inside an array and can use foreach loop to go through all category information.
    
    foreach($categories as $category){
        // do suff with category id $category->cat_ID
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.