All,
I’m using the following code to get all of the defined wordpress menus that are created:
$menus = wp_get_nav_menus();
I know the ID of the menu I want to use. Based on the menu ID I’d like to get the Pages that are in that menu and the corresponding Navigation Label based on a selected menu ID. How can I go about doing that?
I actually discovered this:
$menu_items = wp_get_nav_menu_items($options['menu_choice']);
In that example the $options[‘menu_choice’] is the selected Menu ID but what I really would like is to give the permalink value. Can I get that from this?
Thanks for any help in advance!
That’s exactly what you want.
Now $menu_items is an object that contains all data for all menu items. So you can retrieve necessary data using
foreach
loop.You can find more interesting information for this question, such as orderby options, on official website: http://codex.wordpress.org/Function_Reference/wp_get_nav_menu_items
To access the title and url of each item in a menu using the
wp_get_nav_menu_items()
function:You want to display a specific menu? why not use a simpler function,
wp_nav_menu
, and pass an argument of your desirable menu-ID? just replace your menu_id with $menu_ID in the next example:To get the post ID then you will have to pull it using this function :
$id = get_post_meta( $menu_item->ID, ‘_menu_item_object_id’, true );
Otherwise the id will be the nav_menu custom type post that wordpress uses for the menus.
Same goese for the $url, you can call it using get_permalink($id);