WP_REST_Terms_Controller::get_term() protected WP 4.7.2
Get the term, if the ID is valid.
{} It's a method of the class: WP_REST_Terms_Controller{}
No Hooks.
Return
WP_Term/WP_Error. Term object if ID is valid, WP_Error otherwise.
Usage
// protected - for code of main (parent) or child class $result = $this->get_term( $id );
- $id(int) (required)
- Supplied ID.
Changelog
Since 4.7.2 | Introduced. |
Code of WP_REST_Terms_Controller::get_term() WP REST Terms Controller::get term WP 5.6
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;
}