WP_REST_Menus_Controller::get_term() WordPress Method

The WP_REST_Menus_Controller::get_term() method is used to get a specific menu term from a menu. This is useful for retrieving a menu term by its slug or id.

WP_REST_Menus_Controller::get_term( int $id ) #

Gets the term, if the ID is valid.


Parameters

$id

(int)(Required)Supplied ID.


Top ↑

Return

(WP_Term|WP_Error) Term object if ID is valid, WP_Error otherwise.


Top ↑

Source

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

	protected function get_term( $id ) {
		$term = parent::get_term( $id );

		if ( is_wp_error( $term ) ) {
			return $term;
		}

		$nav_term           = wp_get_nav_menu_object( $term );
		$nav_term->auto_add = $this->get_menu_auto_add( $nav_term->term_id );

		return $nav_term;
	}


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.