[wp-trac] [WordPress Trac] #14331: Tweaks to menu setup page

WordPress Trac noreply at wordpress.org
Thu Mar 19 21:32:11 UTC 2015


#14331: Tweaks to menu setup page
-------------------------------------+-----------------------------
 Reporter:  mrmist                   |       Owner:
     Type:  enhancement              |      Status:  new
 Priority:  normal                   |   Milestone:  Future Release
Component:  Menus                    |     Version:  3.0
 Severity:  normal                   |  Resolution:
 Keywords:  needs-patch ux-feedback  |     Focuses:
-------------------------------------+-----------------------------

Comment (by Stagger Lee):

 Thanks you remanded me about this trac. I found solution, was not very
 easy to find at Google. Not at all I can say.

 This snippet, works wery well. Put all your subcategories in menu editor
 under pparent category. Tweak will make appearance that subcategories
 disappeared, missing in Menu editor too. But dont mind about it, they are
 all there and shows directly if they have at least one Post.


 {{{
 add_filter( 'wp_get_nav_menu_items', 'gowp_nav_remove_empty_terms', 10, 3
 );
 function gowp_nav_remove_empty_terms ( $items, $menu, $args ) {
         global $wpdb;
         $empty = $wpdb->get_col( "SELECT term_taxonomy_id FROM
 $wpdb->term_taxonomy WHERE count = 0" );
         foreach ( $items as $key => $item ) {
                 if ( ( 'taxonomy' == $item->type ) && ( in_array(
 $item->object_id, $empty ) ) ) {
                         unset( $items[$key] );
                 }
         }
         return $items;
 }
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/14331#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list