Menu item in an array

How to get menu items (depth = 1) into an array?

wp_nav_menu displays a formatted list with ul and li elements. wp_list_pages also displays a formatted list with both ul and li.

I just want to get menu items (striped tags) of depth into an array.

How to do it?

+1
source share
2 answers

I think this will help you: wp get navigation menu items

$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; } } 
+3
source

Thanks @Libin

Computed by wp_get_nav_menu_items ()

 $menu_name = 'sidebar-menu'; //menu slug $locations = get_nav_menu_locations(); $menu = wp_get_nav_menu_object( $locations[ $menu_name ] ); $menuitems = wp_get_nav_menu_items( $menu->term_id, array( 'order' => 'DESC' ) ); echo "<pre>"; print_r($menuitems); echo "</pre>"; 

here I get all the menu items

I will give one example here http://wiki.workassis.com/wordpress-get-menu-array/

0
source

Source: https://habr.com/ru/post/910744/


All Articles