Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am looking for a function that will retrieve the names and ids of all categories that will output a checkbox, or give me the data so I can perform a loop.

<input type="checkbox" name="category" value="category_id" /> Category 1
<input type="checkbox" name="category" value="category_id" /> Category 2
<input type="checkbox" name="category" value="category_id" /> Category 3
<input type="checkbox" name="category" value="category_id" /> Category 4
<input type="checkbox" name="category" value="category_id" /> Category 5
share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

this should do it:

$categories = get_categories();
foreach( $categories as $category ) { 
    echo '<input type="checkbox" name=' . $category->slug . '" value="' . $category->term_id . '" /> ' . $category->name . '<br />' . "\n";
}

and you can change/order the list by feeding arguments to get_categories(): http://codex.wordpress.org/Function_Reference/get_categories

share|improve this answer
    
Thank you. This is what I am looking for. –  imHavoc Feb 25 '11 at 1:21
add comment

Your Answer

 
discard

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.