开发者

wordpress, autopost, setting post_date from data date

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.开发者_如何学JAVA

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


This page list parameter accepted by metaWeblog.newPost.

From that page, you can use either 'date_created_gmt' or 'dateCreated' to store date data.


I do this in this way:

  1. Use the Incutio XML-RPC Library for PHP
  2. 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 ??

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜