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.


Top ↑

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 );
}


Top ↑

Changelog

Changelog
VersionDescription
5.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More