Post not updating – error in class-wp-rest-request.php – sanitize_params()
-
I am trying to update posts using the API.
Creating a posts works but updating is not working.
I added logs to class-wp-rest-server.php and to class-wp-rest-request.php to see what’s happening.
I am trying to update something simple, as an example.
data_to_send = {"comment_status": "closed"} json_to_send = json.dumps(data_to_send) response = requests.post(post_url + "/" + postID + "/", headers=header, json=json_to_send)
In class-wp-rest-server.php I see the request
WP_REST_Request Object ( [method:protected] => POST [params:protected] => Array ( [URL] => Array ( [id] => 1122 ) [GET] => Array ( ) [POST] => Array ( ) [FILES] => Array ( ) [JSON] => {"comment_status": "closed"} [defaults] => Array ( ) )
In class-wp-rest-request.php, function sanitize_params() I see that {“comment_status”: “closed”} is received as a string and not as an array and there is a PHP error:
PHP Warning: Invalid argument supplied for foreach() in /home/username/example.com/wp-includes/rest-api/class-wp-rest-request.php
Any idea what’s happening here and how to fix this?
Thanks!
- The topic ‘Post not updating – error in class-wp-rest-request.php – sanitize_params()’ is closed to new replies.