Create post with REST API in php with file_get_contents

Actually I have no problems getting posts. I need to create posts with the REST API in php with file_get_contents. This is my code: json_decode( file_get_contents( “http://my-site.com/wp-json/wp/v2/posts”, false, stream_context_create( array( “http” => array( “header” => “Content-type: text/json\r\n”, “method” => “POST”, “content” => json_encode( array( “slug” => “article-2”, “title” => “Article 2”, “content” => “Created with … Read more

Can we access the REST request parameters from within the permission_callback to enforce a 401 by returning false?

From what I have tried and tested so far, the getters and setters do not work inside the function permission_callback. The alternate way would be to throw a custom 401 from the callback itself. Is it possible to use the permission_callback, check the parameter, and return false instead of writing a custom response in the … Read more

wordpress custom endpoint multiple params

I’m trying to create a route in my store, to receive notifications from an API, but every time I test the route I created, I get this error message No route was found matching the URL and request method function notifications_cbt_func($request) { return $request; } add_action(‘rest_api_init’, function () { register_rest_route( ‘cbt-api/v1’, ‘/notifications/’, array( ‘methods’ => … Read more

WP REST API – Retrieve content from page

I already get posts from categories with: http://domain.com/wp-json/wp/v2/posts?filter[category_name]=category-name but how can i retrieve content from page? – [page_name]=page-name for example but its not working. I have searched lot but cant found any solution. Thanks. 4 Answers 4 To retrieve a page by slug, just use /wp-json/wp/v2/pages/?slug=your-page-name-here, with “your-page-name-here” obviously being the slug of your page.

Get more than 10 posts in a specific category with the wordpress api

I’m currently building an Ionic app that uses the WordPress api. I can retrieve posts in a specific category by using the following: // Retrieve filtered data for the categories to show posts. function getCategoryName(categoryName) { return ($http.get(svampeURL + ‘posts?categories=” + categoryName).then(handleSuccess, handleError)); } The problem is that it only returns 10 as it is … Read more

WordPress REST API “rest_authentication_errors” doesn’t work external queries?

WordPress REST API “rest_authentication_errors” doesn’t work external queries? I was using following experimental codes for experimental purposes. add_filter(‘rest_authentication_errors’, ‘auth’); function auth() { return true; } add_action( ‘rest_api_init’, ‘cors’, 15 ); function cors() { add_filter( ‘rest_pre_serve_request’, function( $value ) { header( ‘Access-Control-Allow-Origin: *’ ); return $value; }); } Then I realized that if we made a … Read more

WordPress wp-json API – Custom Post Type returns 403

I’ve been trying for a full day to get a really basic install of the WP-API to answer to a custom post type (in this case called ‘transactions’). The post type is set up and fully public, and it’s existence is acknowledged by querying example.com/wp-json/posts/types/transactions. I’m getting the expected response from example.com/wp-json/posts?type=page but a 403 … Read more

WP REST API V2 – Modifying responses

I am trying to modify the response object of a WP REST API (v2) call following this guide: http://v2.wp-api.org/extending/modifying/ I have a post type called Careers and a taxonomy called Regions. Both are set to “show_in_rest” => true I am using pretty permalinks. When I GET mydomain/wp-json/wp/v2/careers it returns results as expected. So far so … Read more

Hiding API routes list

When you go to /wp-json or /wp-json/[namespace] on an API-enabled WordPress site, it shows all of the API routes and endpoints. How can I disable this behaviour without disabling the REST API? 2 Answers 2 You can use the filter hook ‘rest_index’ : add_filter(‘rest_index’, function ($response) { $data = $response->get_data(); $data[‘namespaces’] = []; $data[‘routes’] = … Read more