ACF日期选择器从前端删除过去的日期

问题描述 投票:0回答:1

我在高级自定义字段中发布了招聘广告,该广告使用日期选择器字段作为作业添加的结束日期。

    <?php if (have_rows('jobs', 'option')): ?>
        <?php $now = time(); ?>
        <div id="jobs">
            <div class="jobs-title">
                <h2><?php the_field('active', 'option'); ?></h2>
            </div>
            <div class="jobs">
                <div class="inner-jobs flexing">
                    <?php $today = strtotime("now");
                    while (have_rows('jobs', 'option')): the_row();
                        $date_one_timestamp = DateTime::createFromFormat("d/m/y", get_sub_field('job-deadline', 'option'))->getTimestamp();
                        if ($date_one_timestamp > $today) { ?>
                            <div class="flex job flexing">
                                <div class="flex-small">
                                    <div class="bubble flex">
                                        <img src="<?php the_sub_field('job-img', 'option'); ?>">
                                    </div>
                                </div>
                                <div class="flex-cont">
                                    <div class="job-title"><h4><?php the_sub_field('job-title', 'option'); ?></h4>
                                    </div>
                                    <p>Lõpptähtaeg: <?php echo date("y/m/d", $date_one_timestamp); ?></p>
                                    <a href="<?php the_sub_field('job-url', 'option'); ?>" target="_blank">
                                        <button><?php the_sub_field('job-button', 'option'); ?><span
                                                    class="ion-ios-arrow-forward"></span></button>
                                    </a>
                                </div>
                            </div><!-- job -->
                        <?php } else { ?>
                        <?php } ?>
                    <?php endwhile; ?>
                </div><!-- inner -->
            </div><!-- .jobs -->
        </div><!-- #jobs -->
    <?php endif; ?>

我想要实现的是不输出比今天更早的作业添加,这意味着他们不再活跃了。到目前为止,我已经实现了上述目标但是这给出了如下错误:

Fatal error
: Uncaught Error: Call to a member function getTimestamp() on boolean in /data01/virt64863/domeenid/www.xn--t-1gaa.viasat.ee/htdocs/wp-content/themes/mtg/footer.php:16 Stack trace: #0 /data01/virt64863/domeenid/www.xn--t-1gaa.viasat.ee/htdocs/wp-includes/template.php(688): require_once() #1 /data01/virt64863/domeenid/www.xn--t-1gaa.viasat.ee/htdocs/wp-includes/template.php(647): load_template('/data01/virt648...', true) #2 /data01/virt64863/domeenid/www.xn--t-1gaa.viasat.ee/htdocs/wp-includes/general-template.php(76): locate_template(Array, true) #3 /data01/virt64863/domeenid/www.xn--t-1gaa.viasat.ee/htdocs/wp-content/themes/mtg/template-home.php(162): get_footer() #4 /data01/virt64863/domeenid/www.xn--t-1gaa.viasat.ee/htdocs/wp-includes/template-loader.php(74): include('/data01/virt648...') #5 /data01/virt64863/domeenid/www.xn--t-1gaa.viasat.ee/htdocs/wp-blog-header.php(19): require_once('/data01/virt648...') #6 /data01/virt64863/domeenid/www.xn--t-1gaa.viasat.ee/htdocs/index.php(17): require('/data01/virt648. in
/data01/virt64863/domeenid/www.xn--t-1gaa.viasat.ee/htdocs/wp-content/themes/mtg/footer.php
on line
16

有什么建议我可能做错了吗?

javascript php wordpress advanced-custom-fields
1个回答
0
投票

解析此行中的日期似乎有错误:

$date_one_timestamp = DateTime::createFromFormat("d/m/y", get_sub_field('job-deadline', 'option'))

你有没看过这个电话回来的内容:

get_sub_field('job-deadline', 'option')

如果出现错误,函数createFromFormat将返回false(请参阅http://php.net/manual/en/datetime.createfromformat.php

这解释了您尝试在布尔值上调用getTimestamp()的错误消息!

© www.soinside.com 2019 - 2024. All rights reserved.