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 | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Menus | Keywords: | has-screenshots needs-refresh |
Focuses: | ui, administration | Cc: |
Description
Hi,
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)
Change History (9)
#1
@
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.
#2
@
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
@
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 https://make.wordpress.org/core/handbook/tutorials/working-with-patches/#creating-a-patch. Patches should be built from a copy of WordPress trunk (https://develop.svn.wordpress.org/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
@
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 :)
First patch for ticket number #41351