【问题标题】:Updating post_meta in WordPress through XML-RPC通过 XML-RPC 更新 WordPress 中的 post_meta
【发布时间】:2013-02-08 15:07:23
【问题描述】:

我目前正在从事一个项目,该项目涉及从 300 多个静态页面中抓取数据并将该数据传输到 WordPress 网站。我已经使用 Simple Fields (http://simple-fields.com/) 插件设置了各种自定义字段,并且基本的 XML-RPC 连接正常工作。下面是我用来测试注入自定义帖子的内容(用 Ruby 编写):

connection = XMLRPC::Client.new_from_uri "http://localhost:8888/xmlrpc.php"
username   = "admin"
password   = "password"
test_post  = {
  :post_type   => "custom_property",
  :post_status => "draft",
  :post_title  => "test post!",
  :post_meta   => {
    :_simple_fields_fieldGroupID_1_fieldID_3_numInSet_0 => "test"
  }
}
puts connection.call("wp.newPost", 1, username, password, test_post)

我尝试过 :custom_fields 代替 :post_meta 但仍然无济于事。我似乎无法更新通过简单字段创建的自定义字段。

如果有人对如何做有任何建议,将不胜感激。


编辑:通过使用这篇文章扩展 XML-RPC 函数解决了这个问题:http://kovshenin.com/2010/custom-xml-rpc-methods-in-wordpress/

【问题讨论】:

    标签: ruby wordpress xml-rpc


    【解决方案1】:

    实际上,弄清楚 Wordpress 帖子的结构非常棘手。如果是您要发布的自定义字段,则应使用以下格式:

    'custom_fields' => [{'key' => 'something', 'value' => 'something else'}]
    

    如果是自定义分类,使用这个:

    'terms' => {
                'custom_type' => [value],
                'custom_something' => ['array_item','array_item']
            }
    

    对于术语,您总是需要将值放入数组中,即使它只是一项。希望它有所帮助。

    【讨论】:

      猜你喜欢
      • 2019-02-23
      • 1970-01-01
      • 1970-01-01
      • 2013-07-15
      • 2018-05-23
      • 2013-10-21
      • 2012-09-03
      • 1970-01-01
      • 2011-05-18
      相关资源
      最近更新 更多