hide category menus with zero articles

This commit is contained in:
Mark Moser 2018-09-10 08:58:30 -05:00
parent 84e38e80ac
commit 75f1a0058a
2 changed files with 14 additions and 1 deletions

View File

@ -4,7 +4,7 @@
.gitattributes
.gitignore
.no-sync
dev.sync.sh
.git/
sync.dev.sh
dev
dev/

View File

@ -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' );