Wordpress API,包含类别和标签的新帖子(Wordpress API, new post with categories and tags)

系统教程 行业动态 更新时间:2024-06-14 17:01:31
Wordpress API,包含类别和标签的新帖子(Wordpress API, new post with categories and tags)

我在节点中有一个简单的脚本,但问题在于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.

更多推荐

本文发布于:2023-04-20 16:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/88592d050b4cda4f63ebf998b42b617e.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类别   标签   帖子   API   Wordpress

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!