1

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.

  • Oh I've been there mulitple times. If it's on the 1st 3 pages of Google results I've tried it. That exact string comes back with and invalid formatting issue. – curtismchale Oct 8 '12 at 3:39
  • I guess you're simply missing a , in here: ` 'wp.editPost' array` between the Array and the method. You should turn on your debugging environment to catch typos and (even better), use a decent IDE. – kaiser Oct 8 '12 at 8:43
2

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:

$date = new IXR_Date( strtotime( $post->post_date ) );  // Parse the date to an IXR_Date object.

$response = $client->query( 
    'wp.editPost',
    array( 
        0, 
        $user, 
        $pwd,
        $post_id,
        array( 
            'post_date' => $date 
        ) 
    ) 
);
  • Ooops on the missed field. I did actually have it (or the other content wouldn't be updating when I had the date commented out). – curtismchale Oct 8 '12 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.