Send request to WordPress REST API

Since your specific scenario is a remote application making a request to WordPress you’ll need to explore additional authentication methods available via plugins for the REST API. I won’t make any specific recommendations since I don’t know your use case in detail but I’m sure you will find one that works well.

WP Rest API not working

First you’ve to Check if the WordPress REST API is enabled or not The best way to check is to visit this URL: https://yoursite.com/wp-json. If you see some JSON response, REST API is enabled. If it’s showing some error page or returns to home page, REST API is not enabled. Then we’ve to enable it … Read more

Using WordPress RESTapi to call a php file instead of post or page

Make custom API endpoint and move the logic from your PHP file into there instead For example, the code below will create an endpoint in /wp-json/my/v1/video/<id> add_action( ‘rest_api_init’, function() { register_rest_route( ‘my/v1’, ‘/video/(?P<id>\d+)’, [ ‘methods’ => ‘GET’, ‘callback’ => ‘get_video_data’, ‘permission_callback’ => ‘__return_true’, ] ); } ); function get_video_data( $params ) { $video_id = $params[‘id’]; … Read more

WordPress doesn’t send a notification email when submitting a comment using REST API

Here’s an untested suggestion for the REST API case: add_action( ‘rest_after_insert_comment’, ‘wp_new_comment_notify_moderator’ ); emulating the existing: add_action( ‘comment_post’, ‘wp_new_comment_notify_moderator’ ); Note the different callback inputs between actions and that we use that get_comment() should handle both comment ID or comment object as an input.

Cannot get ‘sanitize_callback’ to work for rest parameters

You’re not getting the TESTING because your playlist argument should actually be in the args array like so: (reindented for brevity) register_rest_route( SoundSystem::$rest_namespace, ‘/playlist/new’, array( ‘methods’ => WP_REST_Server::CREATABLE, ‘callback’ => array( __class__, ‘rest_add_playlist’ ), ‘permission_callback’ => function () { return is_user_logged_in(); }, ‘args’ => array( ‘playlist’ => array( ‘description’ => __( ‘JSPF playlist data’, ‘soundsystem’ … Read more

Get all tags not just first 10 with wp api 2.0

If we look at the WP_REST_Controller::get_collection_params() method, we can see the minimum is 1 and the maximum is 100: ‘per_page’ => array( ‘description’ => __( ‘Maximum number of items to be returned in result set.’ ), ‘type’ => ‘integer’, ‘default’ => 10, ‘minimum’ => 1, ‘maximum’ => 100, ‘sanitize_callback’ => ‘absint’, ‘validate_callback’ => ‘rest_validate_request_arg’, ), … Read more

REST API parameters not working with nginx

If your virtual host looks like this: try_files $uri $uri/ /index.php$args; change it to this: try_files $uri $uri/ /index.php$is_args$args; Adding $is_args (which will print a ? character if query arguments are found) will allow WordPress to properly receive and interpret the query parameters

node-wpapi: how to handle authentication?

I’m the author of the node-wpapi library, thanks for checking it out. Unfortunately we do not currently support any external authentication scheme out of the box, because WordPress itself does not ship with any authentication scheme other than the cookie/nonce option (which doesn’t work with external apps, as you describe). There are plugins for authenticating … Read more

Inserting custom post meta value using WP-REST API

Well, there is a way to update post meta. You have to add the update_callback when registering rest field. See the example below: function rest_api_player_meta() { register_rest_field(‘sp_player’, ‘player_meta’, array( ‘get_callback’ => ‘get_player_meta’, ‘update_callback’ => ‘update_player_meta’, ‘schema’ => null, ) ); } function get_player_meta($object) { $postId = $object[‘id’]; return get_post_meta($postId); } function update_player_meta($meta, $post) { $postId … Read more

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