How do you retrieve a post by slug name through REST API?
Posts: sitename.com/wp-json/wp/v2/posts?slug=post-slug Pages: sitename.com/wp-json/wp/v2/pages?slug=page-slug Custom post type: sitename.com/wp-json/wp/v2/POST_TYPE?slug=post-slug
Posts: sitename.com/wp-json/wp/v2/posts?slug=post-slug Pages: sitename.com/wp-json/wp/v2/pages?slug=page-slug Custom post type: sitename.com/wp-json/wp/v2/POST_TYPE?slug=post-slug
This code snippet will hide the users, posts, and comments endpoint results and give 404 as the result, while the rest of the API calls keep running as they were. ::UPDATE:: add_filter(‘rest_endpoints’, function(){ $toRemove = [‘users’, ‘posts’, ‘comments’]; foreach($toRemove as $val) { if (isset($endpoints[‘/wp/v2/’.$val])) { unset($endpoints[‘/wp/v2/’.$val]); } if(isset($endpoints[‘/wp/v2/’.$val.’/(?P<id>[\d]+)’])) { unset($endpoints[‘/wp/v2/’.$val.’/(?P<id>[\d]+)’]); } } return $endpoints; }); … Read more
4.7 has it enabled by default. The easy way to check if it is working is just to visit the example.com/wp-json url, and you should get a list of registered end points there There is no official option to disable it as (at least there was a talk about it not sure if it got … Read more