WP_REST_Menu_Items_Controller::get_menu_id() WordPress Method

The get_menu_id() method is used to get the id of the menu for a given menu item. The menu item must be specified by its id.

WP_REST_Menu_Items_Controller::get_menu_id( int $menu_item_id ) #

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


Parameters

$menu_item_id

(int)(Required)Menu item id.


Top ↑

Return

(int)


Top ↑

Source

File: wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php

	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;
	}


Top ↑

Changelog

Changelog
VersionDescription
5.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.