Get an array of category ids in wordpress?

$cats=  get_categories(array(
    'order'                    => 'ASC',
    'orderby'                  => 'id',

    'hierarchical'             => 0,
    'hide_empty'               => 0,
    'taxonomy'                 => 'edu_year'
));

I would like to produce a variable that contains an array of the IDs of the values retrieved from the get_categories function.

Related posts

Leave a Reply

2 comments

  1. Based on the documentation it returns:

    $category->term_id
    $category->name
    $category->slug
    $category->term_group
    $category->term_taxonomy_id
    $category->taxonomy
    $category->description
    $category->parent
    $category->count
    $category->cat_ID
    $category->category_count
    $category->category_description
    $category->cat_name
    $category->category_nicename
    $category->category_parent
    

    So:

    $output_categories = array();
    $categories=get_categories($args);
      foreach($categories as $category) { 
         $output_categories[$category->cat_ID] = $category->name;
    }
    

    Then $output_categories is exactly what you need.