So let’s say you want to create a custom endpoint for a plugin or theme you are developing. The code is actually fairly simple using register_rest_route.
register_rest_route( ‘myplugin/v1’, ‘/endpoint/(?P
‘methods’ => ‘GET’,
‘callback’ => ‘read_my_posts’
This will create a new route at yoursite.com/wp-json/myplugin/v1/endpoint/[ID]. Then you can set up the function read_my_posts to handle what is returned when this endpoint is reached. I’m not going to dive into too much here, but the official documentation has a fairly good walkthrough on how to get this set up.
This works great when you are just trying to get a list of posts, but what if you want to accept [...]