Home Forums Feature Requests Native ACF JSON API



  • I went searching for a way to access the content of a repeater field via JSON and turned up this thread on the old support forum:

    I’d like to resurrect it and add that, 1. I would find that functionality highly valuable and 2) It would definitely be worth paying for as a premium add-on.

    • Elliot

    • September 5, 2013 at 12:41 pm

    Hi @sirjonathan

    Looks like the simplest answer was hooking in and adding the custom fields like so:

    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);

    The code is so small that I could not charge for it. Maybe you could package it up into a WP plugin?


  • I just added a little variation to retrieve fields from the Option Page. I added the code in this StackOverflow answer

  • Where i use this code? And, how to return the latitude for example? Thanks

    • MagnusN

    • December 17, 2015 at 4:12 am

    Hi Elliot,
    code works fine, since now I get the structure out.
    I’ve come across a weird issue with the output though.
    Here is a snippet from the “custom field” part of the JSON output:

    “custom_fields”: {
    “gallerythumb”: [

    Tried to get the IDs out (“90”, “92”, “91”) so I can store it in an array to which I can reference the different “attachments”, since the urls don’t come with the “custom_fields”.

    Can you spot what the issue is with the output? or does anyone else have a solution for this? Would love to hear some thoughts on this! 🙂

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.