WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#31051 closed enhancement (duplicate)

Programmatically delete nav menu item

Reported by: virgodesign Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.1
Component: Menus Keywords:
Focuses: Cc:

Description

It seems that does not exist a direct fuction for deleting a nav menu item programmatically, using php.
Something such as wp_delete_nav_menu_item, a function that would delete a nav menu item from the database, correctly and definitely.

There is a question partially answered here:

http://wordpress.stackexchange.com/questions/60872/how-do-i-delete-not-exclude-a-menu-item-from-navigation-bar

Using wp_delete_post seems to be a workaround, as it will not update correctly all the databases entries that are involved.

Maybe a working solution could be:

  1. Delete the nav menu item from wp_posts using wp_delete_post (the 8 postmeta options involved will be also deleted).
  2. Delete the nav menu item from wp_term_relationships.
  3. Update the counter of the nav menu in wp_term_taxonomy.

I'm not sure if I'm missing something else, but I think this could be a staritng point. Any suggestions or comments would be very appreciated.

Change History (2)

#1 @tyxla
5 years ago

  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #29728.

#2 @SergeyBiryukov
5 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.