Support » Plugin: ACF to REST API » Don’t showing fields in rest api json

Viewing 3 replies - 1 through 3 (of 3 total)
  • Same problem here,

    function albums_endpoint( $request_data ) {

    // setup query argument
    $args = array(
    ‘post_type’ => ‘albums’,
    ‘posts_per_page’=>-1,
    ‘numberposts’=>-1
    );

    // get posts
    $posts = get_posts($args);

    // add custom field data to posts array
    foreach ($posts as $key => $post) {
    $posts[$key]->acf = get_fields($post->ID);
    $posts[$key]->link = get_permalink($post->ID);
    $posts[$key]->image = get_the_post_thumbnail_url($post->ID);
    $posts[$key]->gallery = acf_photo_gallery(‘ACF_FIELD_NAME’, $post->ID);
    }
    return $posts;
    }

    // register the endpoint
    add_action( ‘rest_api_init’, function () {
    register_rest_route( ‘albums/v1’, ‘/albums/’, array(
    ‘methods’ => ‘GET’,
    ‘callback’ => ‘albums_endpoint’,
    )
    );
    });

    API return ==

    [
    {
    “ID”: 33,
    “post_author”: “1”,
    “post_date”: “2019-01-05 18:45:06”,
    “post_date_gmt”: “2019-01-05 18:45:06”,
    “post_content”: “”,
    “post_title”: “The first test album”,
    “post_excerpt”: “”,
    “post_status”: “publish”,
    “comment_status”: “closed”,
    “ping_status”: “closed”,
    “post_password”: “”,
    “post_name”: “brouillon-auto”,
    “to_ping”: “”,
    “pinged”: “”,
    “post_modified”: “2019-01-05 20:39:26”,
    “post_modified_gmt”: “2019-01-05 20:39:26”,
    “post_content_filtered”: “”,
    “post_parent”: 0,
    “guid”: “http://gyuto.local/?post_type=albums&p=33”,
    “menu_order”: 0,
    “post_type”: “albums”,
    “post_mime_type”: “”,
    “comment_count”: “0”,
    “filter”: “raw”,
    “acf”: {
    “album_title”: “The first test album”
    },
    “link”: “http://gyuto.local/albums/brouillon-auto/”,
    “image”: false,
    “gallery”: []
    }
    ]

    Can someone help siknoidas (@siknoidas) and I 😀

    Thanks

    Thanks for respond. I added question in github, maybe solution is somewhere 🙂

    If you find solution, please write, thanks.

    But it’s working in format – /wp-json/wp/v2/posts/1793

    maybe it’s don’t must working with https://public-api.wordpress.com/rest/v1/sites/155990179/posts/1683 ?

    So, looks like everything working fine. Sorry for disturbing.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.