Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 基于ACF日期时间值从数组中删除自定义帖子类型帖子_Php_Wordpress_Advanced Custom Fields - Fatal编程技术网

Php 基于ACF日期时间值从数组中删除自定义帖子类型帖子

Php 基于ACF日期时间值从数组中删除自定义帖子类型帖子,php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,我想在ACF中按日期时间字段显示帖子。对我的帖子进行排序,以便最接近今天的日期是列表中的第一个,而日期在过去的帖子则不包括在数组中 我尝试了在这里找到的不同解决方案,但运气不好 我的代码是什么样子的: PHP代码:- $today = date('Y-m-d H:i:s'); $posts = get_posts(array( 'posts_per_page' => -1, 'post_type' => 'arrangement', '

我想在ACF中按日期时间字段显示帖子。对我的帖子进行排序,以便最接近今天的日期是列表中的第一个,而日期在过去的帖子则不包括在数组中

我尝试了在这里找到的不同解决方案,但运气不好

我的代码是什么样子的:

PHP代码:-

$today = date('Y-m-d H:i:s');

$posts = get_posts(array(
    'posts_per_page'    => -1,
    'post_type'         => 'arrangement',
    'meta_query'    => array(
                    array(
                        'key'       => 'date',
                        'compare'   => '>=',
                        'value'     => $today,
                    'type'  => 'DATETIME',
                    )
            ),
    'order'             => 'ASC',
    'orderby'           => 'meta_value_num',
    'meta_key'          => 'date',
    'meta_type'         => 'DATE'
));
当我展示帖子时:

<?php while ( have_posts() ) : the_post(); ?>


编辑:使用上面的代码,while循环中会显示日期在过去的帖子,但不会呈现帖子中的数据

如果我没记错的话,ACF会在内部将datetime字段保存为时间戳,因此您必须将元查询更改为数字比较,并使用time()而不是格式化的日期时间。

那么将值更改为:time()并键入数字?只是尝试了一下,结果是帖子中的所有数据都没有呈现出来。在meta_查询中,是的。你看过$prefix_POSTETA中的数据了吗?搜索元键='date'和。。。我刚刚意识到,可能是ACF以毫秒为单位将它们保存为时间戳,所以value应该与time()进行比较,添加三个零,例如
“value”=>time()。“000”
,但只有查看表格才能确定。