Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress API,带有类别和标签的新帖子_Php_Wordpress - Fatal编程技术网

Php Wordpress API,带有类别和标签的新帖子

Php Wordpress API,带有类别和标签的新帖子,php,wordpress,Php,Wordpress,我在node中有一个简单的脚本,但问题是API通常存在 我可以很容易地通过API创建一个新帖子,但我不能向其中添加类别或标签 我的代码: client.newPost({ title: 'title of the post', status: 'publish', type: 'post', content: 'content of the post', categories: ["category1", "category2"] }, functio

我在node中有一个简单的脚本,但问题是API通常存在

我可以很容易地通过API创建一个新帖子,但我不能向其中添加类别或标签

我的代码:

 client.newPost({
    title: 'title of the post',
    status: 'publish',
    type: 'post',
    content: 'content of the post',
    categories: ["category1", "category2"] 
}, function(err, id) {
    if (err) console.log(err)
    else console.log(id)
});
我只粘贴了有趣的部分,因为其他部分效果很好。
我们甚至可以说这些类别是存在的。

在调试wordpress代码库之后,我找到了这个问题的解决方案

正如我所说,这个api是针对NodeWordPress的,但它可能会帮助其他api,因为我在其他地方找不到答案

你只需使用这个

wordpress.newPost({
    title: title,
    status: 'publish',
    type: 'post',
    content: content,
    terms: {
        category: [2],
        post_tag: [3]

    },
    tags: 'bling'


}, function(err, id) {
    if (err) console.log(err)
    else console.log(id)
});
正如你所见,你有“条款” 在它里面,你有“分类”和“贴标签”

目前您只能传递ID,并且它们应该存在于wordpress目的地中,否则它将失败