WP_REST_Terms_Controller::get_term
Get the term, if the ID is valid.
Метод класса: WP_REST_Terms_Controller{}
Хуков нет.
Возвращает
WP_Term|WP_Error. Term object if ID is valid, WP_Error otherwise.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_term( $id );
- $id(int) (обязательный)
- Supplied ID.
Список изменений
| С версии 4.7.2 | Введена. |
Код WP_REST_Terms_Controller::get_term() WP REST Terms Controller::get term WP 7.1.4
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;
}