Beta 4.2: Return the array from the gallery field

I have tried to return the array of ID’s from the ACF’s Gallery field. I assume this should now be possible, but I have failed to find a way. :slight_smile:

Tomorrow I will play with maps, to see if and how could the new goodes be utilized with creating maps that contain dynamic pins based on ACF data.

1 Like

Would love to know how you get on with the maps @Misho esp if it can be via the long/lat

1 Like

@Misho I didn’t try the gallery! I’ll poke around at it, but here’s a thought off the top of my head.

When the Dynamic Content looper initializes, it expects an array and doesn’t really care what is inside.

  • If the item returned is not an array, it will wrap it in an array making it an array with a single value.
  • If the array contains WP_Post, WP_User, or WP_Term objects, it will make those available as the dynamic content context
  • If the array contains scalar values (strings, numbers, etc.) that value will be accessible through the Looper: Current Item dynamic content.

That might be how you can utilize the ID, although it will be tricky to pass that to an image without the dev console until I fix this issue: Adding DC to an image - featured image is gone

Thanks @alexander! I actually wasn’t clear enough. I wanted to dynamically populate a simple WP gallery shortcode, that accepts comma-seaparated IDs.

Oh gotcha! I was able to make some adjustments to allow this:

{{dc:acf:post_field field="gallery"}}

to simply output: 1234,4321,5678 when connected to a Gallery field. Just make sure Image ID is set as the return type of the field. Before making that combined strings it will make sure the incoming values are strings/numbers first so it will output nothing if the types are set to Image array or image object.

Give that a try in the next beta (hopefully tomorrow).

1 Like

Beta 3 is now available with the changes mentioned above.

1 Like

Hi @alexander!

The dynamic output works perfectly on its own: {{dc:acf:post_field field="gallery"}}

However, when part of the Gallery shortcode, it seems it isn’t working?

[gallery ids="{{dc:acf:post_field field="gallery"}}"]

Thanks!

I’ve checked on this, and you’re right, it’s not working in most elements. There are some discrepancies to the order that do_shortcode and Dynamic Content get processed depending on the context. I’ve fixed this for Text, Content Area, and Raw Content, but making sure it works everywhere will take a more involved audit.

1 Like

Those cover over 90% of uses. I’m happy. :slight_smile:

Thanks!

Sounds good! You’re welcome!

1 Like