Skip Navigation

[Resolved] Display Conditional Repeatable Field

This thread is resolved. Here is a description of the problem and solution.

Problem:

Display custom repeating date field by time range.

Solution:

It needs custom codes, for example, you can try these:

https://toolset.com/forums/topic/display-conditional-repeatable-field/#post-1762151

Relevant Documentation:

This support ticket is created 3 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 6 replies, has 2 voices.

Last updated by hansooH 3 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#1762047

Tell us what you are trying to do?
I made a repeatable field to check attendance dates. One member creates a date field up to 50 times a year, but there are too many dates to show multiple dates, so a conditional output date field was created so that only one month can be viewed.
I made the code as below, but nothing is actually displayed. Is there any problem with my code?

[wpv-conditional if="( $(wpcf-attend-dates) eq 'THIS_MONTH' )" debug="true"][/wpv-conditional]

Is there any documentation that you are following?
https://toolset.com/forums/topic/conditionals-and-repeatable-fields/

Is there a similar example that we can see?

What is the link to your site?
hidden link

#1762123

Hello,

How do you setup the custom field "attend-dates"? please take a screenshot for it.
Is it a repeatable field groups or repeating field?

I need to test it in my localhost, thanks

#1762125
주석 2020-08-31 164523.jpg

"attend-dates" is repeating field.
I attached this screenshot

#1762151

Thanks for the details, it needs custom codes, for example, you can try these:
1) Add below codes into your theme file functions.php:

add_shortcode('filter-repeating-date-field', function($atts){
	$atts = shortcode_atts( array(
        'start' => 'this month',
        'end' => 'next month',
        'field' => 'wpcf-attend-dates',
    ), $atts );
	$start = strtotime('first day of ' . $atts['start']);
	$end = strtotime('first day of ' . $atts['end']);
	$field = get_post_meta(get_the_ID(), $atts['field']);
	$arr = array(); 
	foreach($field as $v){
		if($v > $start && $v< $end){
			// setup date format https://developer.wordpress.org/reference/functions/date_i18n/
			$arr[] = date_i18n( get_option( 'date_format' ), $v ); 
		}
	}
	$res = implode(', ', $arr); // here setup the separator
	return $res;
});

2) Use above codes like this:
[filter-repeating-date-field start="this month" end="next month"]

And test again

#1762231

Beautiful, It works. I have one more question. If I want to display this year, can I change like this?

'start' => 'this year',
'end' => 'next year',

#1762233

Yes, you are right, it should be able to work too.

#1762235

My issue is resolved now. Thank you so much! I 🙂

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