When I try to edit custom_fields with wp.editPost. Only edit the other fields, but not custom fields. Custom fields are created again(repeat fields), but will have to be edited.
I am looking: http://codex.wordpress.org/XML-RPC_WordPress_API/Posts#wp.editPost
My array with custom fields is:
$content = array(
'post_id' => (int)$idPostWp,
'title' => $modificarPostWpDecode['title'], //ok edit
'description' => $modificarPostWpDecode['content'], //ok edit
'categories' => $modificarPostWpDecode['category'], //ok edit
'custom_fields' => array(
array('key' => 'precio', 'value' => $modificarPostWpDecodeCustom['price']), // no edit, fields will be create again
array('key' => 'category', 'value' => $modificarPostWpDecodeCustom['category']), // no edit, fields will be create again
array('key' => 'estrenar', 'value' => $modificarPostWpDecodeCustom['new']), // no edit, fields will be create again
array('key' => 'currency', 'value' => $modificarPostWpDecodeCustom['currency']), // no edit, fields will be create again
array('key' => 'search', 'value' => $modificarPostWpDecodeCustom['search']) // no edit, fields will be create again
)
);
My call to wordpress is:
$params = array(1, WPUSER, WPPASS, (int)$idPostWp, $modificarPostWpDecode);
$request = xmlrpc_encode_request('wp.editPost', $params, array('encoding' => 'UTF-8', 'escaping' => 'markup'));
Thank a lot!
As noted here, you must pass the custom field’s ID to edit the field, rather than the key, which would end up creating a duplicate.
So you need to do two requests, unless you already know the custom field IDs. One request to get all the custom data, loop through the fields, and collect the appropriate IDs to the fields you want to update. The second request will update the fields, specified using the field IDs, not just the key.
The collection of IDs can look similar to the following
where
$post
has been collected using thewp.getPost
procedure.You can then proceed as previously, with the following modification to your code.