Opened 13 years ago
Closed 11 years ago
#19776 closed defect (bug) (duplicate)
wp_dropdown_categories (using with taxonomy) defaults if no terms
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Taxonomy | Keywords: | has-patch |
Focuses: | template | Cc: |
Description
the default args for wp_dropdown_categories produce an empty select box when using wp_dropdown_categories for a taxonomy for which there are no terms. I produced this both w/ the filters on the edit.php screen (restrict_manage_posts) and on the front end in my theme. I presume this case never occurs with post categories as there is always Uncategorized.
$args = array( 'show_option_none' => , 'taxonomy' => 'featured', 'hide_if_empty' => false );
lines 340-343 in wp-includes/category-template.php are
if ( ! $r['hide_if_empty'] || ! empty($categories) ) $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n"; else $output = '';
so in a taxonomy that has no terms, the $categories variable is indeed empty, but the default arg is false, so the ! $rhide_if_empty? condition is satisfied and you get the opening of the select input, but you don't get any options therein (since they don't exist. and by default, you don't get any notice of such.
Attachments (4)
Change History (10)
#2
@
13 years ago
- Cc xoodrew@… added
I agree with helgatheviking in presuming that when using wp_dropdown_categories
with categories, it would likely never return nothing because you'll always have the default category in place. Therefore, we shouldn't A) assume the taxonomy is categories
and B) hard-code the string to match. Attached patch changes 'No Categories'
to 'No Terms'
.
#4
in reply to:
↑ 3
@
13 years ago
Replying to linuxologos:
wp_list_categories()
uses "No categories" too.
Yep and realistically that one should be fixed too. If we're going to insist on making named functions versatile like this we should make that versatility plain in the docs too. Opened #19780 to address the change in wp_list_categories()
and category-template.php as a whole.
Maybe it's fair to "force" a
show_option_none
in the case described here, ifshow_option_none
is empty, as is by default forwp_dropdown_categories()
.