我在节点中有一个简单的脚本,但问题在于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) });我只粘贴了有趣的部分,其余部分效果很好。 我们甚至说这些类别存在。
I have a simple script in node, but the problem is with API in general.
I can easily create a new post through the API, but I can't add categories or tags to it.
My code:
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) });I pasted only the interesting part, as the rest works great. Let's even say those categories exist.
最满意答案
调试wordpress代码库后,我找到了这个问题的解决方案。
正如我所说的这个api用于node-wordpress,但它可能有助于其他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) });你可以看到你有“条款”,在里面,你有“category”和“post_tag”。
目前你只能传递id,它们应该存在于wordpress目的地,否则会失败。
After debugging the wordpress codebase, I found the solution for this question.
As I said this api is for node-wordpress, but it may help other apis as I didn't find the answer anywhere else.
You simply use this
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) });As you can see you have "terms" and inside it, you have "category" and "post_tag".
Currently you can only pass ids, and they should exist in the wordpress destination otherwise it will fail.
更多推荐
发布评论