Problem on creating custom endpoints for REST

Writing a custom endpoint is not hard at all. Your code goes to your theme’s functions.php file, or a plugin. After you register a REST route, you can access it via this URL: www.example.com/wp-json/myplugin/v1/foo Also I assume you are missing \ in your callback function’s parameters, as it should be \WP_REST_Request $request.

Why the Path is different with the one coded in rest

No it shouldn’t. The first parameter is called namespace. It’s like the scope for your functions such as this: function my_function(){ $data = 0; } You can only use $data inside that function. Same goes with the REST endpoints. The path /test/ will be available only under its specific namespace. You should choose a unique … Read more

How to use REST API to send user metadata?

I’m not a WP API expert. It sounds like you want to store more information than the API supports, so you will need to add an endpoint – https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/ If you are doing payment processing, I assume you are using a service or plugin + service for that, so you may want your custom endpoints … Read more

How to add / embed an author into REST data from a custom post type?

I found out how to grab each result and add a link. For the ananda_video_audio post type: add_filter( ‘rest_prepare_ananda_video_audio’, function( $results ) { // These two lines are unique to our code of course $video = new Ananda_Video_Audio( $results->data[‘id’] ); $authors = $video->get_author_IDs(); foreach( $authors as $author_id ) { $results->add_link( ‘author’, rest_url( ‘/wp/v2/users/’ . $author_id … Read more