Problem:
I am using multiple instances field OR repeating field to upload photos. I would like to count these photos and show on the page that there are X photos for this post or listing.
Solution:
You can do this by using custom shortcode. Please add this code in your theme’s or child theme’s functions.php file:
add_shortcode( 'count-repeats', 'count_repeat_func' ); function count_repeat_func($atts) { return sizeof(get_post_meta( $atts['post-id'], 'wpcf-' . $atts['field'], false )); }
Then you can use this Shortcode. You should wrap this Shortcode in an HTML Conditional to check if the Field does exist, as other wise unexpected results can be produced:
[count-repeats post-id="[wpv-post-id]" field="url"]
More details: https://toolset.com/forums/topic/how-to-count-repeated-field/#post-412707
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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 12:00 – 17:00 | 12:00 – 17:00 | 12:00 – 17:00 | 12:00 – 17:00 | 12:00 – 17:00 | - |
- | 18:00 – 21:00 | 18:00 – 21:00 | 18:00 – 21:00 | 18:00 – 21:00 | 18:00 – 21:00 | - |
Supporter timezone: Asia/Karachi (GMT+05:00)
This topic contains 4 replies, has 2 voices.
Last updated by 7 years, 4 months ago.
Assisted by: Noman.