[wp-hackers] wp_dropdown_categories and multiple selections
xoodrew at gmail.com
Sat Mar 3 18:48:13 UTC 2012
> Building an awesome widget :-) which includes wp_dropdown_categories
> for one of the options and wanted to add the option to select multiple
> categories and looking at
> doesn't appear to be possible.
> Trying to build a widget that shows posts with thumbnail and excerpt
> that are either most popular, recent, modified, by ID, random or
> alphabetical (by title) with the ability to show on all categories or
> a subset of categories. Basically a widget for popular, recent, random
> posts with thumbnail and excerpt (not seen a widget that covers them
> all in one widget).
> Have it working how I want except the selection of categories.
> Currently can include a single category or exclude a single category
> with a selection options using wp_dropdown_categories, but not include
> or exclude a set of categories using a drop down selection box. I
> don't want to have a widget the user has to find the category IDs and
> add them like 3,7,9 as not user friendly. Want a selection box the
> user holds down CTRL and ticks the categories they want to
> the code is
> <?php wp_dropdown_categories('hierarchical=1&selected='
> .$instance['only']. '&orderby=name&show_count=1&name=' .
> $this->get_field_name('only') . '&hide_empty=0'); ?><br />
> <label for="<?php echo $this->get_field_name('only');
> ?>"><?php _e('Only show posts in this category.',
> 'stallion-wseo-widget'); ?></label>
> $instance['only'] is the Category ID
> The above gives a drop down select box that one category ID can be
> selected from, looking to select more than one.
> I'm using
> . $num);
> For selecting the posts and was trying to use wp_dropdown_categories
> to generate the list of categories to include or exclude.
> Maybe a better question would have been how to generate a comma
> seperated list of categories for the $only variable without the user
> typing them out as 3,8,123 since wp_dropdown_categories doesn't have
> that as a feature :-)
> Any ideas?
> http://www.stallion-theme.com/ Stallion WordPress SEO Theme
> http://www.stallion-theme.com/stallion-wordpress-seo-plugin Stallion
> WordPress SEO Plugin
There's a ticket on the track discussing this very topic:
In your case, I'd echo scribu's sentiment and ask why not just provide a
list of checkboxes as is done with the Categories metabox? UX for a
multiple-select dropdown is awful.
More information about the wp-hackers