Hi,
Thank you for contacting us and I'd be happy to assist.
Using the "wpv-for-each" shortcode, you can get the first instance of the repeating field like this:
( ref: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-for-each )
[wpv-for-each field="wpcf-event-dates" start="1" end="1"]
[types field='event-dates' style='text' format='j M, Y' item='$current_page'][/types]
[/wpv-for-each]
However, it can't be used for getting only the last instance as there is no parameter available for that.
For this reason, you'll need a custom shortcode, that can return the count of repeating field items. Here is a slightly updated code, from Minesh's reply:
( ref: https://toolset.com/forums/topic/conditional-on-amount-of-repeatable-fields/#post-1389441 )
add_shortcode('count_rf_entries', 'func_count_rf_entries');
function func_count_rf_entries($atts, $content){
$atts = shortcode_atts( array(
'field' => '',
'post_id' => get_the_ID(),
), $atts );
$field = get_post_meta($atts['post_id'], "wpcf-".$atts['field'], false);
$res = 0;
if(is_array($field)){
$res = count($field)-1;
}
return $res;
}
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
Next, please add "count_rf_entries" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.
After that, you'll be able to use this shortcode inside the required format of the statement like this:
Event runs
[types field='event-dates' style='text' format='j M, Y' item='$current_page' index='0'][/types]
through
[types field='event-dates' style='text' format='j M, Y' item='$current_page' index='[count_rf_entries field='event-dates']'][/types]
Note: the number that 'count_rf_entries' custom shortcode returns, is 1 less than the actual count of repeating field items because the "index" attribute in the "types" shortcode supports zero-based index (i.e. it starts from '0' and not '1').
( ref: https://toolset.com/documentation/customizing-sites-using-php/functions/#date )
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar