_wp_delete_post_menu_item

Callback for handling a menu item when its original object is deleted.

Description

_wp_delete_post_menu_item( (int) $object_id = 0 ); 

Parameters (1)

0. $object_id — Optional. (int)
The ID of the original object being trashed.

Usage

  1. if ( !function_exists( '_wp_delete_post_menu_item' ) ) { 
  2. require_once ABSPATH . WPINC . '/nav-menu.php'; 
  3.  
  4. // The ID of the original object being trashed. 
  5. $object_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = _wp_delete_post_menu_item($object_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/nav-menu.php  
  1. function _wp_delete_post_menu_item( $object_id = 0 ) { 
  2. $object_id = (int) $object_id; 
  3.  
  4. $menu_item_ids = wp_get_associated_nav_menu_items( $object_id, 'post_type' ); 
  5.  
  6. foreach ( (array) $menu_item_ids as $menu_item_id ) { 
  7. wp_delete_post( $menu_item_id, true );