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've recently discovered that we can insert a dropdown list of categories like this:

define( 'WP_USE_THEMES', false );
require( './wp-load.php' );
wp_dropdown_categories( array(
    'child_of'         => 0,
    'class'            => 'postform', 
    'depth'            => 0,
    'echo'             => 1,
    'exclude'          => '', 
    'hide_empty'       => false, 
    'hide_if_empty'    => false,
    'hierarchical'     => true,
    'id'               => '',
    'name'             => 'cat-dropdown', 
    'order'            => 'ASC',
    'orderby'          => 'name', 
    'selected'         => 0, 
    'show_count'       => 0,
    'show_option_all'  => '', 
    'show_option_none' => __('None'),
    'tab_index'        => 0, 
    'taxonomy'         => 'format',
) );

This is great, BUT what if I want to select multiple categories?

I've come across wp_category_checklist() and tried this code:

function wp_category_checklist( 
    $post_id = 0, 
    $descendants_and_self = 0, 
    $selected_cats = false, 
    $popular_cats = false, 
    $walker = null, 
    $checked_ontop = true 
) {
    wp_terms_checklist( $post_id, array(
        'taxonomy'             => 'category',
        'descendants_and_self' => $descendants_and_self,
        'selected_cats'        => $selected_cats,
        'popular_cats'         => $popular_cats,
        'walker'               => $walker,
        'checked_ontop'        => $checked_ontop
    ) );

But it doesn't output anything.

I'm trying to get a list of my categories on a BLANK PAGE, not within a sidebar or post. Is that possible?

share|improve this question
The code you wrote about wp_category_checklist() above is just the function definition. – RRikesh Jan 14 '13 at 5:50
Right, but wordpress' codex has absolutely no way to explain how to use it. Hence my question. – Sweepster Jan 15 '13 at 1:03
Unfortunately yes. But since it is based on wp_terms_checklist(), you can have a look at the latter to see how it works. – RRikesh Jan 15 '13 at 4:45
but wp_terms_checklist is included in the function and that by itself also does not work. The codex also has nothing to explain how to use that function either. – Sweepster Jan 15 '13 at 12:45
up vote 1 down vote accepted

Here is the answer I ended up with:

$select_cats = wp_dropdown_categories( array( 'echo' => 0 ) );
$select_cats = str_replace( "name='cat' id=", "name='cat[]' multiple='multiple' id=", $select_cats );
echo $select_cats;

It displays a list of my categories that can be multi-selected as per my question. It's a hack of wp_dropdown_categories, but it works.

share|improve this answer

The function wp_terms_checklist is defined in the file /wp-admin/includes/template.php and therefore only available on the admin side of Wordpress.

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.