XMLRPC - wp.newPost 具有自定义 post 类型和自定义字段
XMLRPC - wp.newPost with custom post type and custom fields
我正在尝试通过 XMLRPC 添加新帖子,但出于某种原因我无法添加自定义字段(标题和描述等其他内容有效)。
我使用的伪代码:
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
的自定义字段为空。
看不出我做错了什么。
尝试使用:
custom_fields = {}
custom_fields.update(
{'my_meta_key': 123}
)
元键的命名有问题。我用下划线命名它们,比如 _my_meta_key
,这意味着它们受到 API.
的保护
我正在尝试通过 XMLRPC 添加新帖子,但出于某种原因我无法添加自定义字段(标题和描述等其他内容有效)。
我使用的伪代码:
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
的自定义字段为空。
看不出我做错了什么。
尝试使用:
custom_fields = {}
custom_fields.update(
{'my_meta_key': 123}
)
元键的命名有问题。我用下划线命名它们,比如 _my_meta_key
,这意味着它们受到 API.