JSON API显示高级自定义字段-WordPress [英] JSON API to show Advanced Custom Fields - 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屋!