Accessing private posts through REST API, same code that works in remote doesn’t in local

The problem was that I didn’t completely clone the wp site, and I forgot to install the plugin that I used to manage user roles The plugin is Members (“User Role Editor by Members – Best User, Role and Capability Management Plugin for WordPress”) by MemberPress, and there I can allow the roles that I … Read more

Backbone with custom rest endpoints

From the documentation: Backbone.sync is the function that Backbone calls every time it attempts to read or save a model to the server. By default, it uses jQuery.ajax to make a RESTful JSON request and returns a jqXHR. The sync function may be overridden globally as Backbone.sync, or at a finer-grained level, by adding a sync function to a Backbone collection or to an … Read more

How to send the body in wp_remote_post as “raw”?

I got this one working, you have to pass the json_encoded array on the body parameter of the request. $customer_details = [ ‘first_name’ => $first_name, ‘last_name’ => $last_name, ’email’ => $email, ]; $customer_details[‘body’] = json_encode($customer_details); $customer = $api->createUpdateCustomer($customer_details); public function createUpdateCustomer($customer_details) { $response = $this->apiCall( “2.0/customers”, ‘POST’, $customer_details); $result = json_decode($response); return $result; } public … Read more

WordPress REST Api get posts by ID

You’re getting that mismatched values because you’re using the wrong argument for the post ID in your $args array (i.e. the query args for WP_Query). And the correct argument is p (lowercase P) and not id: $args = [ // ‘id’ => $request[‘id’], // wrong argument name – ‘id’ ‘p’ => $request[‘id’], // and the … Read more

How to include file attachment in ajax submission via the rest_api?

You can really use FormData just like you could use it with the old admin-ajax.php route, but: Set processData and contentType to false. Set the method to POST and make sure your REST API route supports the POST method. $(‘#create-book-form’).submit(function (e) { // var $this = $(this); // what’s this? e.preventDefault(); var data = new … Read more

Making internal rest requests non-blocking?

rest_do_request does not make a HTTP request to the REST API. rest_do_request handles a request object directly. WP_REST_Request and rest_do_request are for handling requests, not making them. This is why your attempt to make it non-blocking failed. If you want to make a non-blocking request to the REST API, you have to make a HTTP … Read more

How to get data from /wp-json/wp/v2/users/me

I was just doing this earlier, if you are trying to simply get user data from your wordpress website with Postman just simply do a request to: /wp-json/wp/v2/users/ or directly to your user number: /wp-json/wp/v2/users/User Number here (you will need ACF to REST API plugin ) so you can see the endpoint acf field below … Read more

Sidebar endpoint using WordPress API

Is there a default endpoint for sidebars? No, I don’t think there is. So (for now), using a custom REST API endpoint does sound like a good option to me. gives me the sidebar not in json format and then a json response with an empty body_response That’s because get_sidebar() echo the output, hence the … Read more

Custom WP API endpoint NULL body data

I have solved the issue. It was unrelated to json / javascript / api. It was a simple issue of tmp folder ownership. Since there were no errors spewing out by the php managing the request, I never noticed a PHP NOTICE saying to check permissions in temp folder as php was unable to upload … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)