python-3.x - 如何通过 python wordpress xmlrpc 提交自定义字段数据
问题描述
我在我的网站上使用 wp 作业管理器。当我尝试通过 xmlrpc 添加列表时,一切都很好,但类别和位置为空。
我的代码如下。你能告诉我我的代码有什么问题吗?谢谢
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import GetPosts
from wordpress_xmlrpc.methods import posts
from wordpress_xmlrpc import WordPressTerm
from wordpress_xmlrpc.methods import taxonomies
wp = Client('http://127.0.0.1/15wp/xmlrpc.php', 'admin', '123456')
# now let's create a new product
widget = WordPressPost()
widget.post_type = 'job_listing'
widget.title = 'Widgetlast02'
widget.content = 'This is the widgets description.'
widget.post_status = 'publish'
widget.custom_fields = []
widget.custom_fields.append({
'job_location': 'Newyork',
'job_listing_category': 'hotel'
})
widget.id = wp.call(posts.NewPost(widget))
解决方案
这只是查看in文档WordPressPost
wordpress_xmlrpc
的猜测:
(强调我的)
类 WordPressPost
表示 WordPress 中的帖子、页面或其他已注册的自定义帖子类型。
- ID
- 用户
- 日期(日期时间)
- date_modified(日期时间)
- 蛞蝓
- post_status
- 标题
- 内容
- 摘抄
- 关联
- 评论状态
- ping_status
- 条款(WordPress 条款列表)
- 术语名称(字典)
- custom_fields (字典)
- 外壳(字典)
- 密码
- post_format
- 缩略图
- 黏
- post_type
它期望custom_fields
是dict
- 您正在创建 alist
然后将 a 插入dict
到该列表中:
widget.custom_fields = []
widget.custom_fields.append({
'job_location': 'Newyork',
'job_listing_category': 'hotel'
})
这可能会更好:
widget.custom_fields = {
'job_location': 'Newyork',
'job_listing_category': 'hotel'
}
推荐阅读
- python-2.7 - 如何将系列数据分成两部分
- sql - PLS-00103:遇到包的符号“CREATE”
- python - 从 2D tensorflow 变量中删除单行(GPU 上的可用内存)
- django - 如何在 django 的输入字段中使用 datetime-local
- dependencies - 微服务输入输出领域模型
- sql - SQL 输出行作为列
- javascript - 传递对象以更新redux中数组中的一个字段
- ios - 在 UINavigationController Stack 的 UIViewController 中关闭 UIAlertController
- javascript - 使用jquery在html中搜索文件名
- unit-testing - 对组合物的模拟使用 spocks 方法计数器?