rest_get_queried_resource_route() WordPress Function
The rest_get_queried_resource_route() function is used to get the route for the currently queried resource. This function is useful for determining the URL for a REST API request. For example, if you are making a request to the WordPress REST API to get a list of posts, you can use this function to get the URL for the request. This function is also useful for debugging purposes. If you are having trouble getting a particular REST API request to work, you can use this function to debug the request.
rest_get_queried_resource_route() #
Gets the REST route for the currently queried object.
Return
(string) The REST route of the resource, or an empty string if no resource identified.
Source
File: wp-includes/rest-api.php
function rest_get_queried_resource_route() { if ( is_singular() ) { $route = rest_get_route_for_post( get_queried_object() ); } elseif ( is_category() || is_tag() || is_tax() ) { $route = rest_get_route_for_term( get_queried_object() ); } elseif ( is_author() ) { $route = '/wp/v2/users/' . get_queried_object_id(); } else { $route = ''; } /** * Filters the REST route for the currently queried object. * * @since 5.5.0 * * @param string $link The route with a leading slash, or an empty string. */ return apply_filters( 'rest_queried_resource_route', $route ); }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.5.0 | Introduced. |