【问题标题】:Create post with custom fields through WP Rest API通过 WP Rest API 创建带有自定义字段的帖子
【发布时间】:2018-02-05 00:53:15
【问题描述】:

我正在做一个 IONIC 应用程序,该项目需要通过带有自定义字段的 Wordpress API 创建一个帖子(我使用 ACF Pro 和 Aires ACF to REST API),我可以使用 REST API 创建一个普通帖子,甚至tho,没有创建或分配 ACF 字段,仅当我在 Wordpress 管理界面中创建帖子时才会为帖子创建它们。

我正在阅读 ACF to REST API 的文档,但我只看到了编辑和显示功能。这是否意味着帖子元必须存在?那么如何为帖子“创建”它们

提前感谢您的帮助

最好的问候

phpadmin 帖子创建:

没有发布元数据:

【问题讨论】:

    标签: wordpress advanced-custom-fields


    【解决方案1】:
    $json = file_get_contents('PATH/TO/FILE.json');
    function the_json_contents($json_to_get){
    
                $json_in_array = json_decode($json_to_get, true); //json string to array
    
                return $json_in_array;
            }
    function do_stuff_do_json() {
        $json_array = the_json_contents($json);
        foreach($json_array['id'] as $js) { //assuming we have an 'id' key
            $somevariable  = $js['someKey'];
            $somevariable2 = $js['someOtherKey'];
        } 
    
    }
    

    参考this solution

    【讨论】:

      猜你喜欢
      • 2018-06-24
      • 2016-06-01
      • 2015-06-10
      • 1970-01-01
      • 2021-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-07
      相关资源
      最近更新 更多