Support » Fixing WordPress » WordPress XMLRPC (wp.newPost) – Can't get post_date formatted right

  • $content = array(
            'post_title' => $title,
            'post_content' => $body,
            'post_status' => 'publish',
            'post_date' => $pub_date //What's the proper format for the date here?
        $params = array(0,$this->settings['username'],$this->settings['password'],$content);
        $request = xmlrpc_encode_request('wp.newPost',$params);

    I’ve tried many different variations for post_date format and none of them worked. Here are all the combinations that I’ve already tried and none of them are working:

    1) $pub_date = date('Y-m-d H:i:s', time());
    2) $pub_date = time();
    3) $pub_date = new IXR_Date(time());
    4) $pub_date = date('c',time());
    5) $datetime = new DateTime('2010-12-30 23:21:46');
       $pub_date = $datetime->format(DateTime::ISO8601);

    It seems like I tested every possible solution and it still doesn’t want to post whenever I try to include post_date. Could someone please help, I’m really stuck on this one.

Viewing 1 replies (of 1 total)
  • Figured it out:

    `$publish_date = ‘20121217T01:47:03Z’ //this is the proper format for datetime
    xmlrpc_set_type($publish_date, ‘datetime’); //xmlrpc_set_type must be used on above date so that XML passes it properly as <dateTime.iso8601> instead of <string>

    $content = array(
    ‘post_title’ => $title,
    ‘post_content’ => $body,
    ‘post_status’ => ‘publish’,
    ‘post_date’ => $publish_date);

    $params = array(0,$this->settings[‘username’],$this->settings[‘password’],$content);
    $request = xmlrpc_encode_request(‘wp.newPost’,$params);

Viewing 1 replies (of 1 total)
  • The topic ‘WordPress XMLRPC (wp.newPost) – Can't get post_date formatted right’ is closed to new replies.