WordPress.org

Ready to get started?Download WordPress

Forums

WordPress XMLRPC (wp.newPost) - Can't get post_date formatted right (2 posts)

  1. clevertechie
    Member
    Posted 1 year ago #

    $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);
        $this->Curl->post($this->controller->rpc_url,$request);

    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.

  2. clevertechie
    Member
    Posted 1 year ago #

    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);
    $this->Curl->post($this->controller->rpc_url,$request);`

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags