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

2 Answers
2

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' );

Leave a Reply

Your email address will not be published. Required fields are marked *