{"id":15332087,"date":"2022-02-05T14:59:56","date_gmt":"2022-02-05T14:59:56","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/post-not-updating-error-in-class-wp-rest-request-php-sanitize_params\/"},"modified":"2022-02-05T15:02:44","modified_gmt":"2022-02-05T15:02:44","slug":"post-not-updating-error-in-class-wp-rest-request-php-sanitize_params","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/post-not-updating-error-in-class-wp-rest-request-php-sanitize_params\/","title":{"rendered":"Post not updating &#8211; error in class-wp-rest-request.php &#8211; sanitize_params()"},"content":{"rendered":"<p>I am trying to update posts using the API.<\/p>\n<p>Creating a posts works but updating is not working.<\/p>\n<p>I added logs to class-wp-rest-server.php and to class-wp-rest-request.php to see what&#8217;s happening.<\/p>\n<p>I am trying to update something simple, as an example.<\/p>\n<pre><code>data_to_send = {&quot;comment_status&quot;: &quot;closed&quot;}\n\njson_to_send = json.dumps(data_to_send)\n\nresponse = requests.post(post_url + &quot;\/&quot; + postID + &quot;\/&quot;, headers=header, json=json_to_send)<\/code><\/pre>\n<p>In class-wp-rest-server.php I see the request<\/p>\n<pre><code>WP_REST_Request Object\n(\n    [method:protected] =&gt; POST\n    [params:protected] =&gt; Array\n        (\n            [URL] =&gt; Array\n                (\n                    [id] =&gt; 1122\n                )\n\n            [GET] =&gt; Array\n                (\n                )\n\n            [POST] =&gt; Array\n                (\n                )\n\n            [FILES] =&gt; Array\n                (\n                )\n\n            [JSON] =&gt; {&quot;comment_status&quot;: &quot;closed&quot;}\n            [defaults] =&gt; Array\n                (\n                )\n\n        )<\/code><\/pre>\n<p>In class-wp-rest-request.php, function sanitize_params() I see that {&#8220;comment_status&#8221;: &#8220;closed&#8221;} is received as a string and not as an array and there is a PHP error:<\/p>\n<p><code>PHP Warning:  Invalid argument supplied for foreach() in \/home\/username\/example.com\/wp-includes\/rest-api\/class-wp-rest-request.php<\/code><\/p>\n<p>Any idea what&#8217;s happening here and how to fix this?<\/p>\n<p>Thanks!<\/p>\n","protected":false},"template":"","class_list":["post-15332087","topic","type-topic","status-publish","hentry","topic-tag-api"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/15332087","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":1,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/15332087\/revisions"}],"predecessor-version":[{"id":15332093,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/15332087\/revisions\/15332093"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=15332087"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}