0

How can I get my menus in an array?

With wp_nav_menu ( );, I will get the list with HTML, but I don't want the HTML tags. I just want the data.

I found this but what is this line for - $menu_name = 'custom_menu_slug';?

    $menu_name = 'custom_menu_slug'; // Get the nav menu based on $menu_name (same as 'theme_location' or 'menu' arg to wp_nav_menu)

    if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ) ) {
    $menu = wp_get_nav_menu_object( $locations[ $menu_name ] );

    $menu_items = wp_get_nav_menu_items($menu->term_id);


        foreach ( (array) $menu_items as $key => $menu_item ) {
            $title = $menu_item->title;
        }
    }

Any ideas?

1 Answer 1

1

It sounds like wp_get_nav_menu_items should do it. If you just want the menu items in an array, you don't need the rest of the code you have there.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks. I have seen that doc. I don't understand and there is no code usage example. Please have a look on this new question I just raised stackoverflow.com/questions/35643423/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.