times / acf-to-wp-api

Puts all ACF fields from posts, pages, custom post types, attachments and taxonomy terms, into the WP-API output under the 'acf' key
http://wordpress.org/plugins/acf-to-wp-api/
MIT License
203 stars 24 forks source link

Media attachment meta output issue when used with ACF Pro Gallery !? #44

Open timkoeck opened 8 years ago

timkoeck commented 8 years ago

Hi there, firstly thank you very much for this awesome plugin. It generally works like a charme and makes working with acf custom fields and the REST API so comfortable!

I might have noticed an issue. Correct me if I am wrong ;)

I am using ACF Pro and added a gallery field:

1

In the next step I added media attachment meta fields that appear for every image uploaded to a gallery. Just for you to understand the intention: Those are two dropdown fields that can set the horizontal and vertical focus point position for an image that is used as a background cover on the frontend (responsive design).

2

So far so good... But here comes the issue: on the frontend side this information is only displayed once within the [acf][bg-showcase-images] node ('bg-showcase-images' is the gallery field-name as you can see on the first screenshot).

But as the meta value can be set individually for each image uploaded to an acf gallery field, I expected it to appear for each image entry of the gallery ([acf][bg-showcase-images][0], [bg-showcase-images][1], [bg-showcase-images][2], ...) which is sadly not the case. In the following screenshot you can see that the attachment meta values img_focus_x and img_focus_y are only once within [acf][bg-showcase-images] and that they don't appear for each image within the gallery:

3

Am I doing something wrong, missing something or is the script not working correctly for this special occasion?

Looking forward to read about your thoughts.

Cheers, Tim

sheriffderek commented 8 years ago

How did you go about adding the media attachment fields?

timkoeck commented 8 years ago

I also used ACF. Just created a new field group and set file attachment as the rule for where to display. You can take a look at the screenshot (sorry, it is german)...

screenshot 2016-04-13 02 12 29
timkoeck commented 8 years ago

Am I doing something wrong? I just implemented the same setup for another project where I am using php to fetch the data. This works as expected. I am fetching the gallery data firstly and in the next step I loop over the image entries. Each image entry has the two parameters.

<?php

    $images = get_field('bg_gallery');

    if ($images): ?>
        <div class="slides">
            <?php foreach( $images as $image ): ?>
                <?php $focus_x = get_field('bg_img_focus_x', $image['ID']); ?>
                <?php $focus_y = get_field('bg_img_focus_y', $image['ID']); ?>
                ....                        
                </div>
            <?php endforeach; ?>
        </div>
    <?php endif; ?>