WP REST API: filter by category 1 AND category 2
Multiple categories can be separated by comma like below http://example.com/wp-json/wp/v2/posts?categories=20,30 hope this helps
Multiple categories can be separated by comma like below http://example.com/wp-json/wp/v2/posts?categories=20,30 hope this helps
Ah I just had this problem myself! And while _embed is great, in my experience it is very slow, and the point of JSON is to be fast 😀 I have the following code in a plugin (used for adding custom post types), but I imagine you could put it in your theme’s function.php file. … Read more
I think the best option is an endpoint. You get all the data as a simple string, so you can decide how it will be parsed, and you don’t have to worry about collisions with other rewrite rules. One thing I learned about endpoints: keep the main work as abstract as possible, fix the glitches … Read more
I have gone through the source, and from what I can see, there aren’t any hooks/filters to tap into changing permissions. My understanding is that this was an intentional design decision. While the REST API was built to be extensible, it is not recommended to modify core endpoints in the way you are asking. There … Read more
You should put the named parameters of the route regex into an optional capturing group: register_rest_route( ‘api’, ‘/animals(?:/(?P<id>\d+))?’, [ ‘methods’ => WP_REST_Server::READABLE, ‘callback’ => ‘get_animals’, ‘args’ => [ ‘id’ ], ] ); The second parameter is simply a regex, thus you can use normal regex logic to make it more complex
Let’s go step by step here. Looks like you’re trying to use OAuth just for authentication, but before you can do so you need to get the Access Token which will be used to authenticate when you make your API calls. Because this is using OAuth version 1, in order to obtain the Access Token … Read more
Why JWT authentication I’m building a site that uses WordPress as the back-end, and a React+Redux app as the front-end, so I’m pulling all the content in the front-end by making requests to the WordPress API. Some requests (mainly, POST requests) must be authenticated, which is when I came across JWT. What we need To … Read more
Is this meant to be used on sites in production? Yes. Many sites have been already using it. Is there a security risk to allowing endpoints to be viewed by anyone, such as /wp-json/wp/v2/users/ which shows all users registered to the site? No. Server responses have nothing to do with security, nothing you can do … Read more
It’s a good point by @Milo, the REST_REQUEST constant is defined as true, within rest_api_loaded() if $GLOBALS[‘wp’]->query_vars[‘rest_route’] is non-empty. It’s hooked into parse_request via: add_action( ‘parse_request’, ‘rest_api_loaded’ ); but parse_request fires later than init – See for example the Codex here. There was a suggestion (by Daniel Bachhuber) in ticket #34373 regarding WP_Query::is_rest(), but it … Read more
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