wordpress中带有自定义字段的PHP倒计时



我想显示截至wordpress内自定义字段中指定日期的剩余天数。我的自定义字段名为bewerbungs_frist。我使用这个代码:

<?php $days = ceil((strtotime("<?php the_field('bewerbungsfrist'); ?>") - time())/(60*60*24));
        $s='';
        if ($days!=1) {
             $s='s';
        }
        echo $days. " days "; ?>

作为输出,我得到大约-1500天。这不可能是对的。有人能帮我吗?

我用这个代码解决了这个问题:

<p>Bewerbungsfrist: <?php $date = DateTime::createFromFormat('Ymd', get_field('bewerbungs_frist'));  echo $date->format('d.m.Y');?></p>
noch <?php $days = ceil((strtotime(get_field('bewerbungs_frist')) - time())/(60*60*24));
echo $days. " Tage "; ?>

您在已打开的标签之间打开了错误的php标签

试试这个

$days = ceil((strtotime(the_field('bewerbungsfrist')) - time())/(60*60*24));

最新更新