To get your expected result, you have to create a second endpoint. Your endpoint doesn’t know what to do with the last part of the path (the ID).
register_rest_route('mytheme/v1/', 'my_cpt/(?P<id>[\d]+)', array(
'methods' => WP_REST_SERVER::READABLE,
'callback' => 'my_cpt_single_result',
));
Your CB function could be like this:
function my_cpt_single_result( $data ) {
$cpt_id = $data['id'];
// make your query with the $cpt_id
}
A little more validation should be done.
It is explained here in a longer version.
Related Posts:
- Fetch All Posts (Including Those Using a Custom Post Type) With WordPress API
- REST API: How can I restrict a custom post type to only be accessible by authenticated users?
- Get the Category Name instead of ID from WP-API
- React post to WordPress custom post type
- How do I get the intended post type of a revision post?
- Custom Post Type not showing in Rest API on Multisite
- Exclude objects from WordPress API based from ACF field using rest_prepare_{$post_type}
- WordPress API for custom post types returns rest_no_route
- How to see posts in taxonomy endpoint
- How to make an API call to a custom post type but filtering by meta value?
- How can I create new CustomPostType record using wp.api.collections?
- How to properly set a value to meta fields of a custom post type in WP-API/node-wpapi REST API?
- Custom post type REST api 404: Updating failed. No route was found matching the URL and request method
- Post current post type to my Ajax
- How to edit feature image with XML RPC?
- Pros and cons of a custom page vs custom post type template file
- Creating tags via API
- How to add/edit advanced custom fields on custom post type’s WordPress REST API?
- How to get all post of custom post type by rest api?
- Get a remote post ID via API given URL
- Create custom post with meta field with AJAX and the WordPress REST API
- CRUD operations in wordpress
- Api rest_route 404 while building filter for custom posts (filtered by multiple meta keys / custom fields)
- How to change the date and time in REST API for comments?
- set_query_params using custom params defined in functions file?
- WP API Response does not show my registered metadata
- REST filters only firing when I have a param set
- WordPress custom API endpoint – how to make the request more flexible
- Creating a WordPress Post via REST API – HTML or Markdown?
- How to add a filter to a custom post type to get adjacent custom posts via the REST API
- How to handle new post from API request?
- Why is wp api returning old acf values?
- wp-json API: not logged in when clicking link to the API from admin mode
- WordPress as a backend for external service? [closed]
- WP REST API and Access-Control-Allow-Origin
- Custom Post Type API doesn’t show taxonomy or category array
- Custom permalink structure for remote content pages
- Use Gravity Forms and a Shopping Cart for output to Freshbooks for an Estimate [closed]
- Fetching custom post type without knowing post type (REST API)
- WordPress REST API V2: “{CUSTOM_POST_TYPE} matches Term ID List and Term ID Taxonomy Query, but should match only one.”
- WordPress REST API – get custom taxonomy category posts
- How to display relations via wordpress Rest API
- Allow REST API Endpoint to specific user and hide from public
- no_rest_route in Unit Testing for REST endpoint for CPT registered via show_in_rest
- Custom endpoint filtering post by custom taxonomies
- wp rest api orderby field in a custom table
- Sync posts via JSON API
- How To Read Read Custom Post Type Data in Headless CMS Mode
- WP_Query: how to search tags in addition to a custom post type?
- How can I sort the results of a REST API response by the title of a connected custom post type?
- Escape commas in REST API
- How to filter a matched value with custom key using WP REST API?
- URL issue retrieving Custom Post Types using Backbone JS API
- register/login api
- WordPress REST API in Integromat: How to overcome “Sorry, you are not allowed to list users / edit this…”
- How to add field to custom post type endpoint
- Create API’s for custom-post types & custom queries using REST or Graphql
- How do i post data to url with fields?
- Action on Custom Post publish
- Use a template for a specific url slug without creating a page
- How to Grab Anime info using Jikan API and fill the value in Metabox
- Help to create the best plugin settings!
- Remove unwanted fields from WP API response
- Get Custom Post types data from the API
- WordPress API “code”:”rest_no_route” with Custom Route
- Adding Amchart Interface to WordPress API
- How to display “META” array in register_taxonomy
- How can I add a meta[] to my custom post type and search by term with the Rest API?
- register_rest_field update_callback don’t work for $_FILES
- Deleting media using the WordPress Rest API
- localize_script or rest api
- Issue with CPT posts within WP REST API showing as []
- Populating Custom Fields from live JSON
- Saving custom post types post_meta over REST-API fails
- WP REST API Custom endpoint don’t work in my plugin
- Extending the API I created to return category names
- filter rest api post by a acf filed
- WordPress API only returning HTML
- Insert custom post data in to MailChimp campaign email
- wp_insert_post not working for custom post type?
- How to dynamically register custom post type
- Store custom post type with JSON content
- querying to custom field over ACF REST API
- Create settings page to enable or disable CPT
- How to update WordPress Plugins in your own maintance application?
- Custom plugin contact form connecting to mailchimp API
- Get all posts of any post type in a category from REST API
- display posts, pages and custom post types from another wordpress site
- External api call using wordpress
- Make term slugs of custom taxonomy available in WP REST API for custom post type?
- Adding Microsoft Teams Incoming Webhook to WordPress, Problem with Rest Route?
- upload image with rest API to the media library
- Woocommerce API for calling products by Category ID
- How to consume external API from WordPress post editor and display the response data in the custom field?
- How to submit a button automatically after every scheduled hours?
- Can’t expose custom field to REST API
- Appointment booking system in WordPress
- i need to resive data external api and show user
- rest_api_init is not getting invoked inside a Class
- Load more post with AJAX