Wordpress XML-RPC 发布到特定类别 [英] Wordpress XML-RPC post to a specific category

查看:32
本文介绍了Wordpress XML-RPC 发布到特定类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了很长时间,但它仍然只发布为未分类",在文档中,它声明使用整数值作为类别 ID,但这不起作用.我还尝试按原样和小写形式编写类别名称,并输入 slug.根据文档,我做的一切都是正确的,但它仍然不起作用!wp.newPost 并且因为它使用 wp_insert_post().

I've been trying for quite a long time and still it posts only as "Uncategorized", In the documentation it's stated to use integer value as category ID, but that doesn't work. I've also tried writing category name as it is and in lowercase and also entering slug. According to documentation I'm doing everything right, but it still doesn't work! wp.newPost and since it uses 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.

Hey I've recently started using the new API.

您应该在新文档中所述的 XML-RPC 请求中使用 terms_names 参数:

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

示例:

您的代码应该更改为如下所示.

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 );
}

我对这个 API 方法有一个问题,但 Post ID 不只返回一个 false 布尔值.如果您在插入类别方面有任何运气以及是否设法收到 POST ID,请告诉我.

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.

这篇关于Wordpress XML-RPC 发布到特定类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆