XMLRPC - 带自定义帖子类型和自定义字段的wp.newPost
问题描述:
我试图在XMLRPC上添加新帖子,但由于某种原因,我无法添加自定义字段(其他内容如标题和说明作品)。XMLRPC - 带自定义帖子类型和自定义字段的wp.newPost
,我使用伪代码:
from xmlrpc import client
user = 'admin'
passwd = 'pass'
server = client.ServerProxy('http://domain.tld/xmlrpc.php')
blog_id = 0
custom_fields = []
custom_fields.append(
{'key' : 'my_meta_key', 'value' : 123}
)
blog_content = {
'post_title': title,
'post_content': content,
'post_type': 'product',
'custom_fields': custom_fields
}
post_id = int(server.wp.newPost(blog_id, user, passwd, blog_content, 0))
帖子被添加,命名my_meta_key
但是我的自定义字段为空。
无法看到我做错了什么。
答
问题是Meta键的命名。我用下划线命名它们,如_my_meta_key
,这意味着它们受API保护。
答
尝试使用:
custom_fields = {}
custom_fields.update(
{'my_meta_key': 123}
)
不工作。无法确定问题出在哪里。通过PHP为同一个键添加后期元作品。 – RhymeGuy
使用dict代替列表后,你得到的错误是什么? –
没有错误。帖子被创建并填充标题和内容。但是,元密钥没有填充。 – RhymeGuy