wpseek.com
A WordPress-centric search engine for devs and theme authors
rest_get_route_for_term › WordPress Function
Since5.5.0
Deprecatedn/a
› rest_get_route_for_term ( $term )
Parameters: |
|
Returns: |
|
Defined at: |
|
Codex: |
Gets the REST API route for a term.
Related Functions: rest_get_route_for_post, rest_get_best_type_for_value, rest_get_url_prefix, rest_get_date_with_gmt, get_the_terms
Source
function rest_get_route_for_term( $term ) { $term = get_term( $term ); if ( ! $term instanceof WP_Term ) { return ''; } $taxonomy = get_taxonomy( $term->taxonomy ); if ( ! $taxonomy ) { return ''; } $controller = $taxonomy->get_rest_controller(); if ( ! $controller ) { return ''; } $route = ''; // The only controller that works is the Terms controller. if ( $controller instanceof WP_REST_Terms_Controller ) { $namespace = 'wp/v2'; $rest_base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name; $route = sprintf( '/%s/%s/%d', $namespace, $rest_base, $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 ); }