Hi there, this is a fun one…
I want to count the number of featured media items inside an ACF repeater gallery so that I can choose to display the default images or just the featured ones. The images have a featured checkbox as pictured.
I was planning to count and set the number of featured items and then use the output with an <If...>
statement to decide which images to display.
I know the below logic is incorrect and should not work, but it’s as close as I can get right now. The logic needs to check each gallery in the repeater and count how many images are ticked as featured.
<Get loop=count />
returns a total, but I can’t see what it’s actually counting.
<!--Set total featured image count-->
<Loop acf_repeater="sim_image_gallery_repeater">
<Loop acf_gallery="sim_image_gallery">
<If acf_checkbox="sim_media_options" any_is value="sim_featured_image">
<Set local="featured_image_total">
<Get loop=count />
</Set>
</If>
</Loop>
</Loop>
The local variable featured_image_total
will be used as below, and this works fine when the total is correct:
<If check="{Get local=featured_image_total}" more_than value="0">
<!--Featured Gallery-->
<Else />
<!--Default Gallery-->
</If>
Maybe there is a simpler solution using <If loop exists...>
but I could not get this work either, so perhaps I need to use some Math here?
Thanks.