Ale*_*dar 2 php wordpress xml-rpc
我已经尝试了很长时间,但它仍然只发布为"未分类",在文档中声明使用整数值作为类别ID,但这不起作用.我也尝试过编写类别名称,并以小写形式输入slug.根据文档我正在做的一切正确,但它仍然无法正常工作! 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 );
}
Run Code Online (Sandbox Code Playgroud)
小智 6
嘿,我最近开始使用新的API.
您应该在XML-RPC请求中使用terms_names参数,如新文档中所述:
http://codex.wordpress.org/XML-RPC_WordPress_API/Posts#wp.newPost
例:
您的代码应该更改为看起来像这样.
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 );
}
Run Code Online (Sandbox Code Playgroud)
我有这个API方法的一个问题,但Post ID不返回false布尔值.如果您有幸插入类别以及是否设法收到POST ID,请告诉我.
| 归档时间: |
|
| 查看次数: |
7430 次 |
| 最近记录: |