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!
Just to be clear, I want to count the number of images in an ACF Gallery field (which might be different than "attachments").
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.
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....
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.
Can I add this to the functions.php file and use a shortcode in my content?
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
Never mind. You've made this so not worth it.
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.