如何将循环值的外部值与外部值进行比较?

发布于 2025-01-31 06:31:55 字数 2142 浏览 4 评论 0原文

我正在尝试编写一个程序,该程序会根据日期比较为我提供输出。我正在使用ACF Repeater,其中设置了一些活动开始日期和活动结束日期。

我有四个不同的事件开始日期,因此我想根据循环中的日期显示结果。这意味着,如果一个软件包的2022年5月23日,第二个软件包具有2022年4月10日,那么当我比较时,结果将获得第一个软件包注册打开的开放,而对于第二个软件包,结果将关闭注册。

我尝试了遵循代码,但它不起作用。

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;
}

I am trying to write a program that gives me output according to date comparison. I am using ACF repeater where I have put some event start dates and event end dates.

I have four different event start dates so I want to show results according to the date within the loop. This means if one package has 23 May 2022 and the second package has 10 April 2022 so when I compare then the result will come for the first package registration open and for the second package the result will come registration close.

I have tried following code but it is not working.

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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文