JSON API显示高级自定义字段-WordPress [英] JSON API to show Advanced Custom Fields - WordPress

查看:121
本文介绍了JSON API显示高级自定义字段-WordPress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个杂志WordPress网站,该网站将为移动应用提供json供稿.我使用高级自定义字段和每个文章中的多个文章和多个页面的转发器字段来设置后端. http://www.advancedcustomfields.com/add-ons/repeater-field/

I am developing a magazine WordPress site that will have a json feed for a Mobile App. I set the backend up using Advanced Custom Fields with a Repeater Field for Multiple Articles and Multiple Pages within each article. http://www.advancedcustomfields.com/add-ons/repeater-field/

我正在使用JSON API,但这不包括我的任何自定义字段.当前是否有可以做到这一点的插件?

I am using the JSON API but this does not include any of my custom fields. Is there currently a plugin that can do this?

推荐答案

@Myke:您为我提供了极大帮助.这是我的卑鄙补充:

@Myke: you helped me tremendously. Here's my humble addition:

add_filter('json_api_encode', 'json_api_encode_acf');


function json_api_encode_acf($response) 
{
    if (isset($response['posts'])) {
        foreach ($response['posts'] as $post) {
            json_api_add_acf($post); // Add specs to each post
        }
    } 
    else if (isset($response['post'])) {
        json_api_add_acf($response['post']); // Add a specs property
    }

    return $response;
}

function json_api_add_acf(&$post) 
{
    $post->acf = get_fields($post->id);
}

这篇关于JSON API显示高级自定义字段-WordPress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆