WordPress Rest API – Get all posts based on post_meta on custom endpoint
WordPress Rest API – Get all posts based on post_meta on custom endpoint
WordPress Rest API – Get all posts based on post_meta on custom endpoint
After much digging, it doesn’t seem to be possible. I did craft some automation with a Node script that basically does this: Check if the name is correct. If it’s not, then download the image, upload with a new name and update the product. If everything goes smooth, delete the original image. Same is repeated … Read more
How to change user avatar using REST API?
You shouldn’t be sending your data as JSON: dataType: “JSON” For add_action(“wp_ajax_nopriv_itempricingfunction” to work, WordPress needs to find the action parameter in your request, which you’re correctly setting here: data: { action : “itempricingfunction”, ean : “EANTEST0101010” }, The problem is that it checks this using $_REQUEST[‘action’], but PHP doesn’t populate $_REQUEST with JSON. It … Read more
First, lets fix your endpoint: function wpc_ylp_rest_videos( ) { $myObj->name = “John”; $myObj->age = 30; $myObj->city = “New York”; $myJSON = json_encode($myObj); echo $myJSON; } There are a few problems here: callbacks for REST API endpoints are meant to return their data, like shortcodes. The REST API does the JSON encoding, you’re not meant to … Read more
Cannot edit post meta fields with rest API
If anybody is strangling with it, the proper solution is to use both wp_set_auth_cookie specifying the second parameter being the logged_in cookie, which now gives me the following code: wp_set_current_user($user_id); if ( wp_validate_auth_cookie( ”, ‘logged_in’ ) != $user_id ) { wp_set_auth_cookie( $user_id ); } And to add an action, as suggested in this thread: Extend … Read more
You shouldn’t pass your nonce to your JavaScript to verify it, since client side scripts can be easily manipulated. Instead, you should get the nonce from your front-end content, and then pass it to server to verify it. After verification, you should decide to output content by server, not by your JavaScript file. Something like … Read more
arguments get_callback and update_callback receive different arguments. try this exemple which works for a field user_continent add_action(“rest_api_init”, function () { register_rest_field( “user” , “user_continent” , [ “get_callback” => function ($user, $field_name, $request, $object_type) { return get_user_meta($user[“id”], $field_name, TRUE); }, “update_callback” => function ($value, $user, $field_name, $request, $object_type) { update_user_meta($user->ID, $field_name, $value); }, ] ); });
So I don’t know what stepTwo.file is, but I presumed it’s a File object instance, and I believe the issue here is that you’re not aware that you didn’t actually need to manually set the Content-Type header because when the request body is a FormData instance, then the content type header will always default to … Read more