WP_REST_Terms_Controller::prepare_links()
Prepares links for the request.
Метод класса: WP_REST_Terms_Controller{}
Хуков нет.
Возвращает
Массив
. Links for the given term.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->prepare_links( $term );
- $term(WP_Term) (обязательный)
- Term object.
Список изменений
С версии 4.7.0 | Введена. |
Код WP_REST_Terms_Controller::prepare_links() WP REST Terms Controller::prepare links WP 6.1.1
protected function prepare_links( $term ) { $links = array( 'self' => array( 'href' => rest_url( rest_get_route_for_term( $term ) ), ), 'collection' => array( 'href' => rest_url( rest_get_route_for_taxonomy_items( $this->taxonomy ) ), ), 'about' => array( 'href' => rest_url( sprintf( 'wp/v2/taxonomies/%s', $this->taxonomy ) ), ), ); if ( $term->parent ) { $parent_term = get_term( (int) $term->parent, $term->taxonomy ); if ( $parent_term ) { $links['up'] = array( 'href' => rest_url( rest_get_route_for_term( $parent_term ) ), 'embeddable' => true, ); } } $taxonomy_obj = get_taxonomy( $term->taxonomy ); if ( empty( $taxonomy_obj->object_type ) ) { return $links; } $post_type_links = array(); foreach ( $taxonomy_obj->object_type as $type ) { $rest_path = rest_get_route_for_post_type_items( $type ); if ( empty( $rest_path ) ) { continue; } $post_type_links[] = array( 'href' => add_query_arg( $this->rest_base, $term->term_id, rest_url( $rest_path ) ), ); } if ( ! empty( $post_type_links ) ) { $links['https://api.w.org/post_type'] = $post_type_links; } return $links; }