I am working on writing my own custom endpoint with the WordPress REST API. I currently have a registered endpoint for a single post using the post's ID.
$version = '1';
$namespace = 'vendor/v' . $version;
$base = 'route';
register_rest_route( $namespace, '/' . $base . /(?P<id>[\d]+)', array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => 'get_data_function',
),
So when I add (?P<id>[\d]+) to the end of the registered rest route that would grab only data for the post with the specific ID. Is this possible to do with the post's slug instead? So the route would be registered the same, but instead of adding (?P<id>[\d]+) I would add something similar that would register it for the post's slug
I was doing some research into this, but couldn't find any information on it