I’m using the code below to create custom menu items on the fly. Its working great, except all menus are created as “Custom”. In the code below, setting the menu-item-type to ‘page’ appears to have no effect.
foreach($thePages as $page){
wp_update_nav_menu_item($menu->term_id, 0, array(
'menu-item-title' => $page->post_title,
'menu-item-type' => 'page',
'menu-item-status' => 'publish')
);
}
wp-includes/nav-menu.php shows that the value is hard coded to “Custom”. However, if I manually add a page to the menu, using the WP Menus manager, it lists it as “Page”, not “Custom”. What can I do to set the menu type to “Page”?
There’s a filter:
Strange it maybe, `post_type’ is the keyword to use:
This will make a menu item just like you manually created one.