How to get the register menu items from "Theme Locations"?

Very simple to get the register menu items,

$locations = get_nav_menu_locations();

Returns an array with the registered navigation menu locations and which menus are assigned to it.

$args = array(
        'order'                     => 'ASC',
        'orderby'                 => 'menu_order',
        'post_type'              => 'nav_menu_item',
        'post_status'            => 'publish',
        'output_key'            => 'menu_order',
        'nopaging'               => true,
        'depth'                    => '0',
        'update_post_term_cache' => false
$nav_items = wp_get_nav_menu_items('964', $args);

Here we have to call the menu directly, so we can't able to swap the menu dynamically. It will return only the "964" menu id.

$nav_items = wp_get_nav_menu_items($locations['menu1'],$args);

But here, whatever you assign the menu in "Theme Loactions". That menu items are returned. So we have easy to swap the menu.


Post a Comment