我一直试图在相当长的时间,它仍然只是张贴的“未分类”,在文档它说用整数值类别ID,但不起作用。 我也试着写的类别名称,因为它是和小写字母,也进入塞。 根据文件,我做的一切权利,但它仍然无法正常工作! wp.newPost和因为它使用wp_insert_post() 。
public function create_post( $title, $body )
{
$title = htmlentities( $title, ENT_NOQUOTES, 'UTF-8' );
$content = array(
'post_category' => array( 18 ), // my category id
'post_type' => 'post',
'post_status' => 'pending',
'post_title' => $title,
'post_content' => $body,
'comment_status' => 'closed',
);
$params = array( 0, $this->username, $this->password, $content );
return $this->send_request( 'wp.newPost', $params );
}
Hey I've recently started using the new API.
You should use the terms_names parameter in your XML-RPC request as stated in the new docs:
http://codex.wordpress.org/XML-RPC_WordPress_API/Posts#wp.newPost
Example:
Your code should be changed to look something like this.
public function create_post( $title, $body )
{
$title = htmlentities( $title, ENT_NOQUOTES, 'UTF-8' );
$content = array(
'post_type' => 'post',
'post_status' => 'pending',
'post_title' => $title,
'post_content' => $body,
'terms' => array('category' => array( 18 ) ),
'comment_status' => 'closed',
);
$params = array( 0, $this->username, $this->password, $content );
return $this->send_request( 'wp.newPost', $params );
}
I have one problem with this API method however, the Post ID is not returned only a false boolean value. Let me know if you have any luck with inserting categories and if you manage to receive the POST ID.
谢谢,这是一个生命的救星! 如果您需要为您的文章提供的标签,你可以用它们传递数组tags_input
属性,就像这样:
$content['tags_input'] = "action, adventure, thriller";
如果你需要在一个特定的时间戳通,你应该使用以下格式
D, d M Y H:i:s +0000
并使用它传递post_date
或post_date_gmt
属性:
$content['post_date_gmt | post_date'] = date("D, d M Y H:i:s +0000", strtotime($your_specific_date_and_time));
希望它可以帮助别人的未来!