WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm building a category picker select list. I just need to populate an array of categorys like so:

$myCats = array("null" => "None (default)", "1" => "Uncategorized", "2" => "Second Category", etc..)

Does WP have an existing method call I can use to pull this data alone? I may need to exclude some categories from the listing too.

share|improve this question
up vote 2 down vote accepted

Can't you use wp_dropdown_categories?

wp_dropdown_categories('show_option_none=Select category&exclude=1,2,3&selected=6');
share|improve this answer
this looks like a viable option. I just need to pass a "selected" value as an argument in my script which is already set up to read an array sequence. Thanks! – Scott B May 10 '11 at 21:33
You can exclude cats with the 'exclude' parameter passing a list of IDs, and you can pass the selected ID with the 'selected' parameter. I edited to add a sample code. – MZAweb May 10 '11 at 21:49

how about just get_categories?

$myCats = get_categories( array( 'exclude'=>'1,2' ) );
$myArray = array();
foreach( $myCats as $cat ){
    $myArray[ $cat->cat_ID ] = $cat->name;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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