Support

Account

Home Forums Feature Requests Native ACF JSON API Reply To: Native ACF JSON API

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

    http://wordpress.org/extend/plugins/json-api/other_notes/#Filter:-json_api_encode http://stackoverflow.com/questions/10132685/json-api-to-show-advanced-custom-fields-wordpress

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

    Thanks
    E