On this page
rest_get_route_for_term( int|WP_Term $term ): string
Gets the REST API route for a term.
Parameters
$termint|WP_Term Required-
Term ID or term object.
Return
string The route path with a leading slash for the given term, or an empty string if there is not a route.
Source
File: wp-includes/rest-api.php. View all references
function rest_get_route_for_term( $term ) {
$term = get_term( $term );
if ( ! $term instanceof WP_Term ) {
return '';
}
$taxonomy_route = rest_get_route_for_taxonomy_items( $term->taxonomy );
if ( ! $taxonomy_route ) {
return '';
}
$route = sprintf( '%s/%d', $taxonomy_route, $term->term_id );
/**
* Filters the REST API route for a term.
*
* @since 5.5.0
*
* @param string $route The route path.
* @param WP_Term $term The term object.
*/
return apply_filters( 'rest_route_for_term', $route, $term );
}
Hooks
- apply_filters( 'rest_route_for_term',
string $route ,WP_Term $term ) -
Filters the REST API route for a term.
Related
Uses
| Uses | Description |
|---|---|
| rest_get_route_for_taxonomy_items() wp-includes/rest-api.php | Gets the REST API route for a taxonomy. |
| get_term() wp-includes/taxonomy.php | Gets all term data from database by term ID. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Used By
| Used By | Description |
|---|---|
| WP_REST_Menu_Items_Controller::prepare_links() wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Prepares links for the request. |
| WP_REST_Menu_Locations_Controller::prepare_links() wp-includes/rest-api/endpoints/class-wp-rest-menu-locations-controller.php | Prepares links for the request. |
| WP_REST_Term_Search_Handler::prepare_item_links() wp-includes/rest-api/search/class-wp-rest-term-search-handler.php | Prepares links for the search result of a given ID. |
| rest_get_queried_resource_route() wp-includes/rest-api.php | Gets the REST route for the currently queried object. |
| WP_REST_Terms_Controller::prepare_links() wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php | Prepares links for the request. |
Changelog
| Version | Description |
|---|---|
| 5.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/rest_get_route_for_term