rest_get_queried_resource_route

函数
rest_get_queried_resource_route ( No parameters )
返回值
  • (string) The REST route of the resource, or an empty string if no resource identified.
定义位置
相关方法
register_rest_routeget_queried_objectrest_ensure_responseget_queried_object_idrest_filter_response_by_context
引入
5.5.0
弃用
-

rest_get_queried_resource_route: 该函数用于检索当前被查询资源的REST API路由。它返回一个字符串,代表当前正在查询的资源的REST API路由。

获取当前被查询对象的REST路由。

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

常见问题

FAQs
查看更多 >