.*?)', array( 'methods' => 'GET', 'callback' => [$this, 'get_post_for_url'] )); }); } public function get_post_for_url($data): \WP_Error|\WP_REST_Response|\WP_Post { $postId = url_to_postid($data['url']); $postType = get_post_type($postId); $request = new WP_REST_Request('GET', "/wp/v2/{$postType}s/{$postId}"); $request->set_url_params(array('id' => $postId)); $controller = new WP_REST_Posts_Controller($postType); return $controller->get_item($request); } }