I’m trying to set the post_date via XML-RPC and keep getting an error saying the XML isn’t formatted properly. The code goes something like:
$post = get_post( $post_id );
$response = $client->query(
'wp.editPost',
array(
0,
$user,
$pw,
array(
'post_date' => $post->post_date
)
)
);
I’m hitting the same issue with wp.newPost
. I know the date should be formatted ISO8601 but I’m just having no luck getting it formatted right.
There are a couple of issues here. First of all,
wp.editPost
takes a fourth parameter before the content struct -> the ID of the post you’re trying to edit (should be an integer).Second, you’re passing a string for the
post_date
, so the client automatically converts this to a<string>
tag before sending it to the server … unfortunately, the server expects a<dateTime.iso8601>
tag.You can fix this by parsing the string date and passing an instance of the
IXR_Date
class instead. The client will parse it properly and the server will react appropriately. I’ve tested the following scenario on my own server: