0

This is referring to the Admin area of Navigation menus

It seems the normal behavior for building out Navigation Menus (Appearance>menus) is that when you expose categories or custom taxonomies, that list only shows terms that are not empty. This is fine behavior, but becomes a pain when trying to build out complex menus when the content is pending.

Does anyone know if there's a method or hook to tell Wordpress to allow empty categories to show up in these lists so they can be selected? Or is using custom links the only real option until content is entered?

update: as noted below, they do show up in the View All tab, but not when you do a Search. Additionally the view all tab is flat and not indented hierarchically.

This is probably an edge case so thanks for bearing with me!

3
  • empty terms show up in the menus section. have you selected the view all tab?
    – Milo
    Feb 20, 2015 at 23:56
  • @Milo ah yes, just noticed this, it's when you do a search, they do not show up.
    – Jesse
    Feb 21, 2015 at 0:05
  • see my answer below to fix that.
    – Milo
    Feb 21, 2015 at 0:37

2 Answers 2

2

In WordPress 4.1.1 at least, In the Menu editor, Categories > View All Tab shows empty categories.

1
  • Yeah ok, 4.1 also does this, I've updated my question, it's search doesn't do it and if you have a lot of cats, it can get cumbersome, esp. since the order of the cats in view all are flat.
    – Jesse
    Feb 21, 2015 at 0:07
0

You can modify the arguments that the search query uses so it will return empty terms. This is a quick hack job, perhaps someone can improve this.

I put it together by looking at the browser console when performing a search. There you can see the parameters it's sending to admin-ajax.php to perform the search. In the case of searching for a term in the category taxonomy, it sets type to quick-search-taxonomy-category. The search itself uses get_terms, which has a filter that lets you modify the arguments before the query. You can see the search function source here.

So I check if it's an AJAX request, check if $_REQUEST['type'] is set, and if it equals quick-search-taxonomy-category, and if so, add a filter to modify the args, where we set hide_empty to false.

function wpd_show_empty_terms_in_quick_search( $args, $taxonomies ){
    $args['hide_empty'] = false;
    return $args;
}

if( defined('DOING_AJAX')
    && DOING_AJAX
    && isset( $_REQUEST['type'] )
    && 'quick-search-taxonomy-category' == $_REQUEST['type'] ){
        add_filter( 'get_terms_args', 'wpd_show_empty_terms_in_quick_search', 10, 2 );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.