• Resolved klol

    (@klol)


    Hi how are you?
    I wanted to know if it was possible not to display my categories of products which are empty in the Max Menu

    I have this code which works well for a “standard” menu but if I put it, the categories which are in the Max Menu, “go out” and are no longer in the column.

    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 ) {
        if ( ! is_admin() ) { 
            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;
    
    }

    If you have a direction to look, it would be a pleasure ^_^
    Have a nice day

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author megamenu

    (@megamenu)

    Hi klol,

    I am good thanks 🙂

    That code looks like it should work (as long as you have also checked it works with a normal menu).

    How are you adding the categories to your columns – are they standard menu items added in the usual way, or are you using a widget to display them?

    Regards,
    Tom

    Thread Starter klol

    (@klol)

    Thank you very much for your answer.

    I added the categories as an item.

    I have a menu like this

    MENU
    – CAT FIRST
    — Item 1
    — Item 2
    – CAT 2
    — Item 1
    — Item 2

    And in Menu I clicked on Max Menu and I created the 3 columns with CAT FIRST, CAT2…

    Thank you have a nice day

    Plugin Author megamenu

    (@megamenu)

    Hi klol,

    What you’re doing sounds correct.

    Can you double check, if you disable MMM on that location (but leave everything else the same), that the categories are definitely removed?

    Regards,
    Tom

    Thread Starter klol

    (@klol)

    Hi Tom,
    Thank you for your answer.

    Yes it’s work fine.

    And when a reactived I have this

    MENU – Cat with product (in the same level)

    And I would like:

    MENU
    – Cat with product

    Sorry I don’t know why.
    Have a nice day

    Plugin Author megamenu

    (@megamenu)

    Hi Klol,

    I think I’ll need to see this in action. Could you set up 2 pages, one page with your default menu, the other with the same menu, but with Max Mega Menu activated? You can do that by creating a new location and outputting it with a shortcode: https://www.megamenu.com/documentation/shortcode/

    Then post the 2 links back here so I can compare them.

    Regards,
    Tom

    Thread Starter klol

    (@klol)

    Oh Gosh,
    I’m so sorry!

    In fact Cat with product, is a child of CAT2, and my product was not in the main category.

    I must now find a solution so that all my sellers do not forget to check the main category ^_^

    Thanks a lot for your help

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Do not display empty product categories’ is closed to new replies.