How to Pull ALL Posts, Categories, or Tags in WordPress REST API
According to the documentation, the correct argument is per_page
According to the documentation, the correct argument is per_page
I’ve created a reduced test case that demonstrates that what you want to do is achievable: add_action( ‘rest_api_init’, function() { register_rest_route( ‘wpse/343039’, ‘route’, [ ‘methods’ => [ ‘POST’ ], ‘permission_callback’ => function( WP_REST_Request $request ) { if ( ‘1’ == $request->get_param( ‘param’ ) ) { return true; } else { return false; } }, ‘callback’ … Read more
For the search endpoint, the object type (the first parameter for register_rest_field()) is search-result and not the post type (e.g. post, page, etc.). So try with this, which worked for me: add_action( ‘rest_api_init’, function () { // Registers a REST field for the /wp/v2/search endpoint. register_rest_field( ‘search-result’, ‘excerpt’, array( ‘get_callback’ => function ( $post_arr ) … Read more
You’re using the wrong endpoint. Look at the documentation. id is not one of the parameters for the posts endpoint. The correct way to retrieve a post with the ID of 1 is: /wp-json/wp/v2/posts/1
I would just hook into determine_current_user filter and check HTTP basic auth data to return the user. Maybe, just maybe, I would allow only specific user to be logged via HTTP auth. That could be done, for example, by setting an user option. The code could look like something like this (tested by OP): add_filter( … Read more
How to change user avatar using REST API?
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
No, you are not passing cookies with jQuery AJAX calls .. certainly not via Cross-domain access. If you’re going to use jQuery to pass data, you need to pass the current user ID and use get_userdata($userid) to determine whether the user has the correct capabilities. Server side: $jQuery_user = get_userdata($_POST[‘user_id’]); if(!user_can($jQuery_user,’publish_posts’)){ return array(‘reply’=>0,’error’=>’Forbidden’,’code’=>’403′); } Client … Read more
Create post using rest api with html content
We can create route using rest_api_init action like : Simply add below code to your theme functions.php file. add_action( ‘rest_api_init’, function () { register_rest_route(‘wp/v2’, ‘forgot_password’, array( ‘methods’ => array(‘GET’, ‘POST’), ‘callback’ => ‘forgot_password’ )); } ); function forgot_password(){ // YOUR CALLBACK FUNCTION STUFF HERE } forgot_password will define route URL address. methods will define which … Read more