Wordpress XML-RPC发布到特定类别


Wordpress XML-RPC post to a specific category

我已经尝试了很长时间,但它仍然只发布为"未分类",在文档中,声明使用整数值作为类别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 );
}

嘿,我最近开始使用新的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 );
}

然而,我对这个API方法有一个问题,PostID并不是只返回一个假布尔值。如果您在插入类别方面有任何运气,并且您是否能够收到POST ID,请告诉我。

谢谢,这是救命稻草!如果您需要为您的帖子提供标签,您可以使用tags_input属性在数组中传递它们,如下所示:

$content['tags_input'] = "action, adventure, thriller";

如果你需要通过一个特定的时间戳,你应该使用以下格式

D, d M Y H:i:s +0000

并使用CCD_ 2或CCD_

$content['post_date_gmt | post_date'] = date("D, d M Y H:i:s +0000", strtotime($your_specific_date_and_time));

希望它将来能帮助到别人!