Skip Navigation

[Resolved] Count Attached Images (ACF Gallery)

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 9 replies, has 2 voices.

Last updated by Ed 1 year, 6 months ago.

Assisted by: Minesh.

Author
Posts
#2466701

Ed

Good morning,
If a post only has 1 image, it's automatically displayed as the featured image.

I want to add a gallery on one of my pages, but only if there are multiple images attached.

Is there way to do this? I believe the solution at the following link is on the right track:

https://toolset.com/forums/topic/count-number-of-images-attached/

I actually DO want to count the number of "attached images."

Thank you!

#2466707

Ed

Just to be clear, I want to count the number of images in an ACF Gallery field (which might be different than "attachments").

#2467023

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

This question is more related to ACF about how you can count the number of images added to ACF field.

Here are the few links that may help you:
- hidden link
- hidden link

Or

You can check with ACF support and if there is any help you require for Toolset, you are welcome to get in touch with us.

#2467125

Ed

Thanks for your response, Minesh.

Let's imagine for a minute that I'm using a Toolset gallery field and not an ACF gallery field.

Same question....

#2467129

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

The source of the Toolset Gallery image field would be the image repeating field.

So, to count the number of instances of your image repeating field, you will have to use the get_post_meta():

For exmaple:

global $post;
$images = get_post_meta($post->ID,'wpcf-image-field');
echo count($images);

Where:
- replace image-field with your original image field slug.

#2467141

Ed

Can I add this to the functions.php file and use a shortcode in my content?

#2467143

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Yes - the code lines I shared with previous message should be wrapped with custom shortcode and you can add it either to funcitons.php file or "Custom Code" section offered by Toolset:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

Make sure your shortcode should return the number of count.

Here is the related ticket that may help you:
- https://toolset.com/forums/topic/conditional-on-amount-of-repeatable-fields/#post-1389441

#2467157

Ed

Never mind. You've made this so not worth it.

#2467395

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok. if things are sorted or you got the idea how to query the repeating field instances, you are welcome to mark resolve this ticket.

#2470013

Ed

Quest abandoned.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.