1

I have been able to add menu items with this statement, this however creates a flat menu. The menu has been created already. I just need to add items.

    wp_update_nav_menu_item(4, 0, array('menu-item-title' =>  __($post_title), 'menu-item-url' => home_url('/'.$url.'/'), 'menu-item-status' => 'publish'));

this is super simple to use. How do I add a sub-menu item?

4
  • Did you created menu with submenus.?
    – Kvvaradha
    Commented Dec 1, 2015 at 2:24
  • 1
    It is not clear what you are asking. Besides there are numerous "nav menu" questions here. I have written answer to some very complicated problems. Have you searched the site at all?
    – s_ha_dum
    Commented Dec 1, 2015 at 3:11
  • I have searched and nothing is exactly what I am looking for. I just want to add things to an existing menu...
    – blenkhn
    Commented Dec 2, 2015 at 1:00
  • Please check my answer
    – blenkhn
    Commented Dec 2, 2015 at 8:50

1 Answer 1

0

I have found what I was looking for the function returns an id of the menu item needed.

    $my_menu_id = wp_update_nav_menu_item(4, 0, array('menu-item-title' => __($my_menu_title), 'menu-item-url' => home_url('/'.$url.'/'), 'menu-item-parent-id' => $my_menu_id, 'menu-item-status' => 'publish')); 

by knowing the menu id you can then create sub menus attached to the first menu item using the menu-item-parent-id

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.