On this page
rest_get_route_for_taxonomy_items( string $taxonomy ): string
Gets the REST API route for a taxonomy.
Parameters
$taxonomystring Required-
Name of taxonomy.
Return
string The route path with a leading slash for the given taxonomy.
Source
File: wp-includes/rest-api.php. View all references
function rest_get_route_for_taxonomy_items( $taxonomy ) {
$taxonomy = get_taxonomy( $taxonomy );
if ( ! $taxonomy ) {
return '';
}
if ( ! $taxonomy->show_in_rest ) {
return '';
}
$namespace = ! empty( $taxonomy->rest_namespace ) ? $taxonomy->rest_namespace : 'wp/v2';
$rest_base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
$route = sprintf( '/%s/%s', $namespace, $rest_base );
/**
* Filters the REST API route for a taxonomy.
*
* @since 5.9.0
*
* @param string $route The route path.
* @param WP_Taxonomy $taxonomy The taxonomy object.
*/
return apply_filters( 'rest_route_for_taxonomy_items', $route, $taxonomy );
}
Hooks
- apply_filters( 'rest_route_for_taxonomy_items',
string $route ,WP_Taxonomy $taxonomy ) -
Filters the REST API route for a taxonomy.
Related
Uses
| Uses | Description |
|---|---|
| get_taxonomy() wp-includes/taxonomy.php | Retrieves the taxonomy object of $taxonomy. |
| 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_Taxonomies_Controller::prepare_links() wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php | Prepares links for the request. |
| rest_get_route_for_term() wp-includes/rest-api.php | Gets the REST API route for a term. |
| WP_REST_Terms_Controller::prepare_links() wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php | Prepares links for the request. |
| WP_REST_Terms_Controller::get_items() wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php | Retrieves terms associated with a taxonomy. |
| WP_REST_Posts_Controller::prepare_links() wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Prepares links for the request. |
Changelog
| Version | Description |
|---|---|
| 5.9.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/rest_get_route_for_taxonomy_items