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
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
"attend-dates" is repeating field.
I attached this screenshot
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
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',
Yes, you are right, it should be able to work too.
My issue is resolved now. Thank you so much! I 🙂