Skip Navigation

[Résolu] Display Conditional Repeatable Field

Ce fil est résolu. Voici une description du problème et la solution proposée.

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 Il y a 3 années et 7 mois. 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.

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
- 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)

Marqué : ,

This topic contains 6 réponses, has 2 voix.

Last updated by hansooH Il y a 3 années et 7 mois.

Assisted by: Luo Yang.

Auteur
Publications
#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.