WordPress.org

Make WordPress Core

Opened 18 months ago

Last modified 18 months ago

#19776 new defect (bug)

wp_dropdown_categories (using with taxonomy) defaults if no terms

Reported by: helgatheviking Owned by:
Priority: normal Milestone: Awaiting Review
Component: Template Version:
Severity: normal Keywords: has-patch
Cc: xoodrew@…

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 18 months ago.
19776.2.patch (886 bytes) - added by linuxologos 18 months ago.
19776.3.patch (897 bytes) - added by linuxologos 18 months ago.
Hopefully a better effort…
19776.4.patch (892 bytes) - added by DrewAPicture 18 months ago.
'No Categories' becomes 'No Terms'

Download all attachments as: .zip

Change History (8)

linuxologos18 months ago

comment:1 linuxologos18 months 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.

Version 0, edited 18 months ago by linuxologos (next)

linuxologos18 months ago

linuxologos18 months ago

Hopefully a better effort...

DrewAPicture18 months ago

'No Categories' becomes 'No Terms'

comment:2 DrewAPicture18 months 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 18 months ago by DrewAPicture (previous) (diff)

comment:3 follow-up: linuxologos18 months ago

wp_list_categories() uses "No categories" too.

comment:4 in reply to: ↑ 3 DrewAPicture18 months 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 18 months ago by DrewAPicture (previous) (diff)
Note: See TracTickets for help on using tickets.