Make WordPress Core

Opened 7 years ago

Last modified 5 years ago

#41351 new defect (bug)

Searching for a category returns nothing if category is empty

Reported by: jackjohansson's profile jackjohansson Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Menus Keywords: has-screenshots needs-refresh
Focuses: ui, administration Cc:



In the navigation menu creation page, when you are trying to add a category to the menu, if the category is empty, it won't show up in the search results. However, if the category itself is empty but has a child that is not empty, it will still be shown.

I have a blog with over 500 categories, and I'm trying to add some of them to the menu but they have no posts yet. Navigating through category list is going to take time, and is also frustrating.

Now I've tracked down the issue to /wp-admin/includes/nav-menu.php, ( starting at line 588 ) but can't find a filter or hook to do so.

This line (109) seems to be responsible for doing the search:

$terms = get_terms( $matches[2], array(
    'name__like' => $query,
    'number' => 10,

According to the documentations, this function accepts an argument for showing empty terms 'hide_empty' => false, but I can't see such option in this part of core's code. I've added this option to the core (temporarily) to see if it solves the issue, and it does.

The other get_term() functions withing this template file mostly use 'hide_empty' => false so I'm not sure either this one was overlooked or not, I tagged this as a bug though.

Attachments (3)

#41351.patch (462 bytes) - added by jackjohansson 7 years ago.
First patch for ticket number #41351
#41351.2.patch (45.5 KB) - added by jackjohansson 7 years ago.
Second patch which fully resolves the issue, both js and no-js
#41351.3.patch (4.2 KB) - added by jackjohansson 7 years ago.
Third patch, includes resolving a PHP warning, created from 4.9-alpha-40870-src.

Download all attachments as: .zip

Change History (9)

7 years ago

First patch for ticket number #41351

#1 @jackjohansson
7 years ago

I've added the first patch that simply includes the empty taxonomies in the results. I'm working on another patch that also allows the user to enable/disable this feature by using a checkbox.

7 years ago

Second patch which fully resolves the issue, both js and no-js

#2 @jackjohansson
7 years ago

I've added the second patch. This updates 3 files, wp-admin/includes/nav-menu.php, wp-admin/js/nav-menu.js and the minified version of it wp-admin/js/nav-menu.min.js.

This patch is tested for categories, tags and custom taxonomies, both under AJAX and while having js disabled.

What this patch does it basically sending an extra argument to the server, allowing the user the include/exclude empty taxonomies from the list.

Feedbacks from testers are appreciated.

#3 @afercia
7 years ago

  • Focuses ui added
  • Keywords has-patch has-screenshots added
  • Version 4.8 deleted

Thanks @jackjohansson! Worth noting that minified (and RTL) files shouldn't be patched: they're generated during the build process. For more details, see Patches should be built from a copy of WordPress trunk ( not from the stable version. Trunk comes with test and development tools and doesn't include minified files.

As per the checkbox, maybe the best option would be to just include empty taxonomies by default. "Decisions not options" is one of the WordPress development philosophies. But I'd propose to keep it as is for now an see what other people think.

Note: I get a Notice: Undefined index when the request is used for checked() at line 754.

Screenshot of the proposed checkbox:

#4 @jackjohansson
7 years ago

Thank you both for your interest in this patch and your kind reply. @afercia

This was my first patch, although I tried to investigate before uploading, but that trunk was hidden on me.

If you mean a PHP error, then that's right. I should have checked if the key is set or not. However this will be resolved after the checkbox is set to checked by default.

Need to deal with the core behavior now, it automatically unchecks every checkbox on initiation/navigation-away :)

7 years ago

Third patch, includes resolving a PHP warning, created from 4.9-alpha-40870-src.

#5 @jackjohansson
7 years ago

The final working patch has been uploaded. It has:

  • the checkbox enabled by default
  • Resolved PHP warning

#6 @welcher
5 years ago

  • Keywords needs-refresh added; has-patch removed

@jackjohansson the patch no longers applies cleanly - can you refresh?

Note: See TracTickets for help on using tickets.