2013-02-25 68 views
1

我正在通過php創建一個新的wp博客帖子。我如何獲得博客帖子ID的回覆? 我可以想到的一種方法是獲取最新的博客帖子ID,但我想要一個更簡單的方法來做到這一點。wordpress php發佈新博客,如何獲得回覆?

<?php 
require_once("IXR_Library.php.inc"); 

$client->debug = true; //Set it to false in Production Environment 

$title="Blog Title"; // $title variable will insert your blog title 
$body="Blog Content"; // $body will insert your blog content (article content) 

$category="category1, category2"; // Comma seperated pre existing categories. Ensure that these categories exists in your blog. 
$keywords="keyword1, keyword2, keyword3"; 

$customfields=array('key'=>'Author-bio', 'value'=>'Autor Bio Here'); // Insert your custom values like this in Key, Value format 

    $title = htmlentities($title,ENT_NOQUOTES,$encoding); 
    $keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding); 

    $content = array(
     'title'=>$title, 
     'description'=>$body, 
     'mt_allow_comments'=>0, // 1 to allow comments 
     'mt_allow_pings'=>0, // 1 to allow trackbacks 
     'post_type'=>'post', 
     'mt_keywords'=>$keywords, 
     'categories'=>array($category), 
     'custom_fields' => array($customfields) 
    ); 

// Create the client object 
$client = new IXR_Client('Your Blog Path/xmlrpc.php'); 

$username = "USERNAME"; 
$password = "PASSWORD"; 
$params = array(0,$username,$password,$content,true); // Last parameter is 'true' which means post immideately, to save as draft set it as 'false' 

// Run a query for PHP 
if (!$client->query('metaWeblog.newPost', $params)) { 
    die('Something went wrong - '.$client->getErrorCode().' : '.$client->getErrorMessage()); 
} 
else 
    echo "Article Posted Successfully"; 
?> 

回答

1

,而不是與

else 
    echo "Article Posted Successfully"; 

使用結束:

$ID = $client->getResponse(); 
if ($ID) 
    echo 'Article Posted Successfully. ID = '.$ID; 
+0

工作就像一個魅力,謝謝! – Bwyss 2013-02-27 09:24:53