From 75f1a0058aa25a7b122abd29bd3cc1fc4884d452 Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Mon, 10 Sep 2018 08:58:30 -0500 Subject: [PATCH] hide category menus with zero articles --- .no-sync | 2 +- functions.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.no-sync b/.no-sync index 2911349..75da5d3 100644 --- a/.no-sync +++ b/.no-sync @@ -4,7 +4,7 @@ .gitattributes .gitignore .no-sync -dev.sync.sh .git/ +sync.dev.sh dev dev/ diff --git a/functions.php b/functions.php index 01cbac1..a19f2a2 100644 --- a/functions.php +++ b/functions.php @@ -76,6 +76,19 @@ function ildi_register_sidebars() { ); } +function ildi_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; +} +add_filter( 'wp_get_nav_menu_items', 'ildi_nav_remove_empty_terms', 10, 3 ); + + // add_action('init', 'register_ildi_menu'); add_action( 'after_setup_theme', 'register_ildi_menus', 0 ); add_action( 'wp_enqueue_scripts', 'ildi_styles' );