Skip to content

Instantly share code, notes, and snippets.

@cdmz
Created January 25, 2016 16:09
Show Gist options
  • Save cdmz/4e938b156274f92dcccf to your computer and use it in GitHub Desktop.
Save cdmz/4e938b156274f92dcccf to your computer and use it in GitHub Desktop.
get item menu wordpress
function get_menu_items($menu){
$args = array(
'order' => 'ASC',
'orderby' => 'menu_order',
'post_type' => 'nav_menu_item',
'post_status' => 'publish',
'output_key' => 'menu_order',
'nopaging' => true,
'update_post_term_cache' => false
);
$items = wp_get_nav_menu_items( $menu, $args );
$menu = array();
if($items){
foreach($items as $item ) {
if($item->menu_item_parent){
$menu[$item->menu_item_parent][] = array(
'title' => $item->title,
'permalink' => $item->url,
'post_type' => $item->post_type
);
}else{
$menu[$item->ID][] = array(
'title' => $item->title,
'permalink' => $item->url,
'post_type' => $item->post_type
);
}
}
}
return (!$menu) ? null : $menu;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment