How to add an endpoint for my custom post type? /wp-json/wp/v2/posts is working but it didn’t in the custom post

The “register_rest_field” function will add and handle data update for a given endpoint, looks like it’s not what you are looking for.

The register_post_type() function accepts a “show_in_rest” and “rest_base” params if you want to use a custom slug for the endpoint:

https://codex.wordpress.org/Function_Reference/register_post_type

By default it uses the WP_REST_Posts_Controller class to handle the methods (get, update, delete content), this means that you can refer to the following documentation:

https://developer.wordpress.org/rest-api/reference/posts/

There are already a few parameters you can pass for filtering (https://developer.wordpress.org/rest-api/reference/posts/#list-posts), but if you want to alter the results/order returned on the GET method to suit your custom needs, you have to pass a custom class for the REST controller param(“rest_controller_class”) in the register_post_type() function.