如何比较循环值之内的当前日期?
我有一些活动日期,例如以下屏幕截图,为此我正在使用ACF中继器。
我有一个功能,我试图将票证注册开始日期与当前日期进行比较。
function santy_shortcode_race_categories_event_post(){
date_default_timezone_set('Asia/Kolkata');
$result = '<div class="table-responsive">
<table class="table table-bordered" style="text-align:center; background-color:#fff;">
<thead>
<tr class="table-head">
<th>Package</th>
<th>Age Category</th>
<th>Ticket Price</th>
<th>Reg. Link</th>
</tr>
</thead>
<tbody>';
$id = get_the_ID();
$current_date = date("Y-m-d H:i:s");
if( get_field('Race-Categories', $id) ) {
while( the_repeater_field('Race-Categories', $id) ) {
$event_start_date .= date("Y-m-d H:i:s", strtotime("+5 hours +30 minutes", strtotime(get_sub_field("ticket_registration_start"))));
$event_end_date .= date("Y-m-d H:i:s", strtotime("+5 hours +30 minutes", strtotime(get_sub_field("ticket_registration_end_date"))));
$result .='<tr>';
$result .='<td>'.get_sub_field("package").'</td>';
$result .='<td>'.get_sub_field("age_category").'</td>';
$result .='<td>'.get_sub_field("ticket_price").'</td>';
if($current_date > $event_start_date){
$result .= '<td>Registration Open</td>';
}else{
$result .= '<td>Registration Close</td>';
}
$result .='</tr>';
}
}else{
$result .='No Any Race categories allocated for this event. Try other events.';
}
$result .= '</tbody>
</table>
</div>';
return $result;
}
但这是返回错误的输出,在我的输出的屏幕截图下方分享。
它在每个行注册中都显示,但从逻辑上讲,它应该关闭注册,并仅显示注册为2 km家族的注册-跑步。
I have some dates for my tickets for the event like the following screenshot and I am using ACF repeater for this.
And I have a function where I am trying to compare the ticket registration start date with the current date.
function santy_shortcode_race_categories_event_post(){
date_default_timezone_set('Asia/Kolkata');
$result = '<div class="table-responsive">
<table class="table table-bordered" style="text-align:center; background-color:#fff;">
<thead>
<tr class="table-head">
<th>Package</th>
<th>Age Category</th>
<th>Ticket Price</th>
<th>Reg. Link</th>
</tr>
</thead>
<tbody>';
$id = get_the_ID();
$current_date = date("Y-m-d H:i:s");
if( get_field('Race-Categories', $id) ) {
while( the_repeater_field('Race-Categories', $id) ) {
$event_start_date .= date("Y-m-d H:i:s", strtotime("+5 hours +30 minutes", strtotime(get_sub_field("ticket_registration_start"))));
$event_end_date .= date("Y-m-d H:i:s", strtotime("+5 hours +30 minutes", strtotime(get_sub_field("ticket_registration_end_date"))));
$result .='<tr>';
$result .='<td>'.get_sub_field("package").'</td>';
$result .='<td>'.get_sub_field("age_category").'</td>';
$result .='<td>'.get_sub_field("ticket_price").'</td>';
if($current_date > $event_start_date){
$result .= '<td>Registration Open</td>';
}else{
$result .= '<td>Registration Close</td>';
}
$result .='</tr>';
}
}else{
$result .='No Any Race categories allocated for this event. Try other events.';
}
$result .= '</tbody>
</table>
</div>';
return $result;
}
But this is returning wrong output, going share below the screenshot of my output..
It is showing in every row registration open but logically it should be show registration closed and show only registration open for 2 km Family-Run.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您的问题是您在循环的每个实例中加入日期,应该分配:
尝试更改以下内容:
对此:
I think your issue is that you are concatenating the dates in each instance of the loop and should be assigning:
Try changing this:
To this: