Custom Nav Menu items default to ‘menu-item-type’ => ‘custom’. How to make a “page” menu item?

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”?

Related posts

Leave a Reply

2 comments

  1. There’s a filter:

    function wpse15368_update_menu_item_type( $args )
    {
        return $args['menu-item-type'] = 'page';
    }
    add_action( 'wp_update_nav_menu_item', 'wpse15368_update_menu_item_type' );
    
  2. Strange it maybe, `post_type’ is the keyword to use:

    'menu-item-object' => 'page',
    'menu-item-type' => 'post_type',
    'menu-item-object-id' => $post_id
    

    This will make a menu item just like you manually created one.