Reputation: 157
I have 2,000 pieces of data I want to import into my wordpress, as wp has many features that work nicely. I started doing it manually but then realized, that its easier to write a script to import it.
everything runs perfect!! one problem, I cannot get it to use the RELEASEDATE of my data as the POSTED date.
I have spend 2 days googling and using SO for resources, and everyone comes close, but some of the answers use wp inner coding structure which I do not want to do. Here is what I have so far:
$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',
'publish' =>$pubdate,
'mt_keywords'=>$keywords,
'categories'=>array($category)
);
$params = array(0,$username,$password,$content,true);
$request = xmlrpc_encode_request('metaWeblog.newPost',$params);
$ch = curl_init();
That all works perfect but I cannot get the date to work. RELEASEDATE is formatted exactly like WP, 2011-03-04 14:33:21 etc.
It prints the date on the post, but the "posted" says the day i ran the script. in the above example I am sending RELEASEDATE to $pubdate. I know that the post_date is an object but not sure how to implement it here.
In short if i let this scrip run full I will have 2,000 post dated today!! :P
Upvotes: 1
Views: 1064
Reputation: 11
I do this in this way:
Code should looks like this:
$client = new IXR_Client('http://wp-blog.com/xmlrpc.php');
$post = array(
'post_type'=> 'post',
'title' => $title,
'description' => $description,
'date_created_gmt' => new IXR_Date(time()),
);
if (!$client->query('metaWeblog.newPost', '', $login, $password, $post, true))
{
die( 'Error while creating a new post' . $client->getErrorCode() ." : ". $client->getErrorMessage());
}
$post_id = $client->getResponse();
For me this works like a charm :-)
More detailed description about ISO8601 and XML date format can be found here: How to scedule a Post using XMLRPC / metaWeblog.newPost ??
Upvotes: 1