不确定自定义分类法,但是我以前使用过此代码来删除空类别。您可以将其添加到函数中。php。
add_filter( \'wp_get_nav_menu_items\', \'nav_remove_empty_category_menu_item\', 10, 3 );
function nav_remove_empty_category_menu_item ( $items, $menu, $args ) {
global $wpdb;
$nopost = $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, $nopost ) ) ) {
unset( $items[$key] );
}
}
return $items;
}