W3cubDocs

/WordPress

WP_REST_Terms_Controller::get_term( int $id )

Get the term, if the ID is valid.

Description

Parameters

$id

(int) (Required) Supplied ID.

Return

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

Source

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

protected function get_term( $id ) {
		$error = new WP_Error( 'rest_term_invalid', __( 'Term does not exist.' ), array( 'status' => 404 ) );

		if ( ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) {
			return $error;
		}

		if ( (int) $id <= 0 ) {
			return $error;
		}

		$term = get_term( (int) $id, $this->taxonomy );
		if ( empty( $term ) || $term->taxonomy !== $this->taxonomy ) {
			return $error;
		}

		return $term;
	}

Changelog

Version Description
4.7.2 Introduced.

© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_rest_terms_controller/get_term