Wordpress - Set Published Date

Posted by danit on Stack Overflow See other posts from Stack Overflow or by danit
Published on 2010-04-11T14:09:21Z Indexed on 2010/04/11 14:13 UTC
Read the original article Hit count: 452

Filed under:

Using this function:

function wpPostXMLRPC($title,$body,$rpcurl,$username, 
$password,$category,**$pubdate**,$keywords='',$encoding='UTF-8') 
    { 
    $title = htmlentities($title,ENT_NOQUOTES,$encoding); 
    $keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding); 
    $content = array( 
        'title'=>$title, 
        'description'=>$body, 
        'mt_allow_comments'=>1,  // 1 to allow comments 
        'mt_allow_pings'=>0,  // 1 to allow trackbacks 
        'post_type'=>'post',
        'post_status' => 'draft',
        **'post_date' =>$pubdate,**
        'mt_keywords'=>$keywords, 
        'categories'=>array($category) 
    ); 
    $params = array(0,$username,$password,$content,true); 
    $request = xmlrpc_encode_request('metaWeblog.newPost',$params); 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request); 
    curl_setopt($ch, CURLOPT_URL, $rpcurl); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 1); 
    $results = curl_exec($ch); 
    curl_close($ch); 
    return $results; 
    }

My Code:

$title = $correctdataandtime;
$body = '<a href="' . $links['alternate'] . '" />' . '<img src="' . $links['image'] . '" />' . '</a>';
$pubdate = date("Y-m-d H:i:s", $datetime);

    //Default Settings
$rpcurl = 'http://vl3.co.uk/xmlrpc.php'; 
$username = 'admin'; 
$password = '3cdsbvre'; 
$category = '1'; //default is 1, enter a number here. 
$keywords = 'Twitter';//keywords comma seperated. 
$encoding ='UTF-8';//utf8 recommended

wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$pubdate,$category,$keywords,$encoding); 

Output of $pubdate is: 2010-04-05 19:25:31

However it still sets the published date as the date and time when i run the script.

© Stack Overflow or respective owner

Related posts about Wordpress