Question

I have the following code that prints a comma separated list which I need in the form of an array, how do I get the list of id's into an array called $excluded_categories with contents as per below?

$categories = get_categories(array('taxonomy'=>'projects_category', 'exclude'=>7, 'orderby'=>'id'));
if ( !empty( $categories ) ) :
foreach($categories as $term){
    echo $term->term_id.', '; // prints: 1,2,3,4,5,6,8,9,
    }
endif;

$excluded_categories would be an array containing: 1,2,3,4,5,6,8,9

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top