Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
    
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
add comment

1 Answer 1

up vote 2 down vote accepted

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 
        ) 
    ) 
);
share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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