WordPress at a glance
function is not described

WP_REST_Post_Search_Handler::detect_rest_item_route() WP 5.0.0

Attempts to detect the route to access a single item.

This is a method of the class: WP_REST_Post_Search_Handler

No Hooks.

Return

String. REST route relative to the REST base URI, or empty string if unknown.

Usage

$WP_REST_Post_Search_Handler = new WP_REST_Post_Search_Handler();
$var = $WP_REST_Post_Search_Handler->detect_rest_item_route( $post );
$post(WP_Post) (required)
Post object.

Changelog

Since 5.0.0 Introduced.

Code of WP REST Post Search Handler::detect rest item route: wp-includes/rest-api/search/class-wp-rest-post-search-handler.php WP 5.2.2

<?php
protected function detect_rest_item_route( $post ) {
	$post_type = get_post_type_object( $post->post_type );
	if ( ! $post_type ) {
		return '';
	}

	// It's currently impossible to detect the REST URL from a custom controller.
	if ( ! empty( $post_type->rest_controller_class ) && 'WP_REST_Posts_Controller' !== $post_type->rest_controller_class ) {
		return '';
	}

	$namespace = 'wp/v2';
	$rest_base = ! empty( $post_type->rest_base ) ? $post_type->rest_base : $post_type->name;

	return sprintf( '%s/%s/%d', $namespace, $rest_base, $post->ID );
}