WordPress.org

Make WordPress Core

Opened 12 months ago

Last modified 9 months ago

#45298 reviewing defect (bug)

Menu Quick Search: Allow searching for empty taxonomy terms

Reported by: birgire Owned by: audrasjb
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Menus Keywords: has-screenshots has-patch 2nd-opinion has-unit-tests
Focuses: administration Cc:
PR Number:

Description

In the Menu admin page /wp-admin/nav-menus.php we can view empty taxonomy terms, but we can't search for empty ones.

This was reported here: https://wordpress.stackexchange.com/questions/302406/how-to-show-empity-category-in-admin-menus-search

I had a look and found the same behavior in the Customizer.

This seems like a bug.

Screenshots:

See screenshots below for categories (same applies for other taxonomies).

Fixes:

The default of get_terms() is to hide empty taxonomy terms.

To fix this here, we need to add:

'hide_empty' => false,

to the input of get_terms() in _wp_ajax_menu_quick_search():

https://core.trac.wordpress.org/browser/tags/4.9.8/src/wp-admin/includes/nav-menu.php#L109

and to the input of get_terms() in WP_Customize_Nav_Menus::search_available_items_query:

https://core.trac.wordpress.org/browser/tags/4.9.8/src/wp-includes/class-wp-customize-nav-menus.php#L352

Attachments (8)

quick-menu-searching-for-empty-categories.jpg (73.1 KB) - added by birgire 12 months ago.
empty-category-not-searchable-in-customizer.jpg (63.0 KB) - added by birgire 12 months ago.
category-setup.jpg (64.7 KB) - added by birgire 12 months ago.
Category setup for the screenshots
menu-items-taxonomies-settings-fixed.png (36.6 KB) - added by audrasjb 9 months ago.
Here is the settings used to reproduce the issue
menu-items-taxonomies-menuscreen-fixed.png (20.8 KB) - added by audrasjb 9 months ago.
Fixed in menu screen
menu-items-taxonomies-customizer-fixed.png (12.8 KB) - added by audrasjb 9 months ago.
Fixed in customizer screen
45298.diff (936 bytes) - added by audrasjb 9 months ago.
Add empty categories to Menu quick search tool in both Menu screen and Customizer screen.
45298-2.diff (4.3 KB) - added by birgire 9 months ago.

Download all attachments as: .zip

Change History (12)

@birgire
12 months ago

Category setup for the screenshots

#1 @audrasjb
9 months ago

  • Owner set to audrasjb
  • Status changed from new to reviewing

Hi, thanks for the ticket,

I agree, we should list empty categories. Here is a first patch (simply adds empty terms to the search tools).

But, I'm wondering about adding post count as well…

Cheers,

Jb

@audrasjb
9 months ago

Here is the settings used to reproduce the issue

@audrasjb
9 months ago

Fixed in menu screen

@audrasjb
9 months ago

Fixed in customizer screen

@audrasjb
9 months ago

Add empty categories to Menu quick search tool in both Menu screen and Customizer screen.

#2 @audrasjb
9 months ago

  • Keywords has-patch 2nd-opinion added

#3 @birgire
9 months ago

  • Keywords has-unit-tests added

Thank you for the patch @audrasjb

45298-2.diff adds unit tests for both cases (i.e. for the Admin Menu page and the Customizer).

It also adjusts the test in WP_Customize_Nav_Menus::search_available_items_query that assumed that the Uncategorized category would not show up in the quick search results.

@birgire
9 months ago

#4 @audrasjb
9 months ago

  • Milestone changed from Awaiting Review to Future Release
Note: See TracTickets for help on using tickets.