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

<?php
define( 'WP_USE_THEMES', false );
require( './wp-load.php' );
?>
<?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',
                        )); ?>

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

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

<?php 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 what I want 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

2 Answers 2

up vote 1 down vote accepted

Here is the answer:

$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;
share|improve this answer
    
Please explain why that could solve the problem. –  toscho Jan 15 '13 at 5:05
    
Because 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. –  Sweepster Jan 15 '13 at 12:45

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

 
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.