【问题标题】:XMLRPC - wp.newPost with custom post type and custom fieldsXMLRPC - 具有自定义帖子类型和自定义字段的 wp.newPost
【发布时间】:2016-10-02 10:03:44
【问题描述】:

我正在尝试通过 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 的自定义字段为空。

看不出我做错了什么。

【问题讨论】:

    标签: python wordpress xml-rpc


    【解决方案1】:

    尝试使用:

    custom_fields = {}    
    custom_fields.update(
             {'my_meta_key': 123}
    

    )

    【讨论】:

    • 不工作。不能真正发现问题出在哪里。通过 PHP 为同一个键添加后期元工作。
    • 使用 dict 而不是 list 后出现什么错误?
    • 没有错误。帖子被创建并填充标题和内容。但是元键未填充。
    • 可以参考以下链接:link
    【解决方案2】:

    问题在于元键的命名。我用下划线命名它们,比如_my_meta_key,这意味着它们受 API 保护。

    【讨论】:

      猜你喜欢
      • 2014-12-26
      • 1970-01-01
      • 2014-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-09
      相关资源
      最近更新 更多