Make WordPress Core

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: helgatheviking's profile helgatheviking 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)

19776.patch (846 bytes) - added by linuxologos 13 years ago.
19776.2.patch (886 bytes) - added by linuxologos 13 years ago.
19776.3.patch (897 bytes) - added by linuxologos 13 years ago.
Hopefully a better effort…
19776.4.patch (892 bytes) - added by DrewAPicture 13 years ago.
'No Categories' becomes 'No Terms'

Download all attachments as: .zip

Change History (10)

@linuxologos
13 years ago

#1 @linuxologos
13 years ago

  • Component changed from General to Template
  • Keywords has-patch added

Maybe it's fair to "force" a show_option_none in the case described here, if show_option_none is empty, as is by default for wp_dropdown_categories().

Last edited 13 years ago by linuxologos (previous) (diff)

@linuxologos
13 years ago

Hopefully a better effort...

@DrewAPicture
13 years ago

'No Categories' becomes 'No Terms'

#2 @DrewAPicture
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'.

Last edited 13 years ago by DrewAPicture (previous) (diff)

#3 follow-up: @linuxologos
13 years ago

wp_list_categories() uses "No categories" too.

#4 in reply to: ↑ 3 @DrewAPicture
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.

Last edited 13 years ago by DrewAPicture (previous) (diff)

#5 @nacin
11 years ago

  • Component changed from Template to Taxonomy
  • Focuses template added

#6 @wonderboymusic
11 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

#19780 is more exhaustively patched - helgatheviking, perhaps weigh in over there, there's been more recent activity

Note: See TracTickets for help on using tickets.