Help with wp_update_nav_menu_item
-
I’m using the function wp_update_nav_menu_item to build my main navigation menu programmatically.
I call my function:
function my_add_pages_to_menu ( $mymenu, $menuID, $post ) {
if ( ‘majorcd’ != $post->post_type )
return;
// Add here the code for adding the page to nav menu
$perma = get_permalink( $post->ID );$itemData = array(
‘menu_item_db_id’ => 0,
‘menu-item-object-id’ => $post->ID,
‘menu-item-parent-id’ => 0,
‘menu-item-position’ => 2,
‘menu-item-type’ => ‘custom’, //$post->post_type,
‘menu-item-title’ => $post->post_title,
‘menu-item-url’ => $perma,
‘menu-item-status’ => ‘publish’
);wp_update_nav_menu_item($menuID, 0, $itemData);
}The problem that I encounter is:
if I use: ‘menu-item-type’ => ‘custom’,
then instead of assigning: ‘menu-item-object-id’ => $post->ID, as I intended, wp_update_nav_menu_item assigns:
$args[‘menu-item-object-id’] = $menu_item_db_id;
==> not at all as I desired because I need the $post->ID later in my design.On the other hand, if I choose to use:
‘menu-item-type’ => $post->post_type,
then wp_update_nav_menu_item assigns:
$args[‘menu-item-url’] = ”;
and I end up with a menu that doesn’t point to any url thus is useless to me.2 questions:
1) Why wp_update_nav_menu_item acts like this ?
2) How can I get to the desired nav-menu? – one that has both clickable titles and has the info of the ID of the page that it is pointing to?I can not change wp_update_nav_menu_item because it is a WP function I can only change my functions, that are in my theme…
Thanks a lot, in advance, to anyone who can answer either of my questions,
Efrat
The topic ‘Help with wp_update_nav_menu_item’ is closed to new replies.