0

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
3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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