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?
Here is the answer I ended up with:
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.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.If you want to select multiple custom taxonomy with checkbox. You can use that code..
And Tf You want to select multiple categories with checkbox. You can use that code..