WP_REST_Menu_Items_Controller::get_menu_id()protectedWP 5.9.0

Gets the id of the menu that the given menu item belongs to.

Method of the class: WP_REST_Menu_Items_Controller{}

No Hooks.

Return

Int.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_menu_id( $menu_item_id );
$menu_item_id(int) (required)
Menu item id.

Changelog

Since 5.9.0 Introduced.

WP_REST_Menu_Items_Controller::get_menu_id() code WP 6.4.3

protected function get_menu_id( $menu_item_id ) {
	$menu_ids = wp_get_post_terms( $menu_item_id, 'nav_menu', array( 'fields' => 'ids' ) );
	$menu_id  = 0;
	if ( $menu_ids && ! is_wp_error( $menu_ids ) ) {
		$menu_id = array_shift( $menu_ids );
	}

	return $menu_id;
}