On this page
WP_REST_Terms_Controller::prepare_links( WP_Term $term ): array
Prepares links for the request.
Parameters
$termWP_Term Required-
Term object.
Return
array Links for the given term.
Source
File: wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php. View all references
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;
}
Related
Uses
| Uses | Description |
|---|---|
| rest_get_route_for_taxonomy_items() wp-includes/rest-api.php | Gets the REST API route for a taxonomy. |
| rest_get_route_for_post_type_items() wp-includes/rest-api.php | Gets the REST API route for a post type. |
| rest_get_route_for_term() wp-includes/rest-api.php | Gets the REST API route for a term. |
| rest_url() wp-includes/rest-api.php | Retrieves the URL to a REST endpoint. |
| add_query_arg() wp-includes/functions.php | Retrieves a modified URL query string. |
| get_term() wp-includes/taxonomy.php | Gets all term data from database by term ID. |
| get_taxonomy() wp-includes/taxonomy.php | Retrieves the taxonomy object of $taxonomy. |
Used By
| Used By | Description |
|---|---|
| WP_REST_Menus_Controller::prepare_links() wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php | Prepares links for the request. |
| WP_REST_Terms_Controller::prepare_item_for_response() wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php | Prepares a single term output for response. |
Changelog
| Version | Description |
|---|---|
| 4.7.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_rest_terms_controller/prepare_links