使用今天的ACF日期>查询自定义发布类型自定义、日期、类型、今天

由网友(临风纵欢)分享简介:我正在使用PHP 7.3.5and wordpress 5.2.x。我有以下自定义帖子类型:register_post_type('Calendar-Events', array('supports' => array('title', 'editor', 'thumbnail', 'custom-fields', '...

我正在使用PHP 7.3.5and wordpress 5.2.x

我有以下自定义帖子类型:

register_post_type('Calendar-Events', array(
    'supports' => array('title', 'editor', 'thumbnail', 'custom-fields', 'excerpt', 'comments', 'revisions'),
    'public' => false,
    'show_ui' => true,
    'exclude_from_search' => true,
    'menu_position' => 5,
    'labels' => array(
        'name' => 'Calendar Events',
        'add_new_item' => 'Add New Calendar Event',
        'edit_item' => 'Edit Calendar Event',
        'all_items' => 'All Calendar Events',
        'singular_name' => 'Calendar Event',
    ),
    'menu_icon' => 'dashicons-calendar-alt',
));
明明我的显卡是GT9800的独立显卡 但是今天吧系统从装了 现在看不一样了

我的帖子类型有一个名为ce_timestamp的自定义字段,它是Date Time Picker使用ACF Version 5.8.7创建的。

我正在尝试查询ce_timestamp字段晚于今天的所有帖子。

我尝试了以下操作:

$today = date('d/m/Y');

try {
    $args = array(
        'post_type' => 'Calendar-Events',
        'posts_per_page' => -1,
        'post_status' => 'publish',
        'meta_query' => array(
            array(
                'key' => 'ce_timestamp',
                'value' => $today,
                'type' => 'DATE',
                'compare' => '>='
            )
        ),
        'meta_key' => 'ce_timestamp',
    );

    $upcomingEvents = new WP_Query($args);

    if ( $upcomingEvents->have_posts() ) {

        while ( $upcomingEvents->have_posts() ) {

            $upcomingEvents->the_post();

            // now $query->post is WP_Post Object, use:
            // $query->post->ID, $query->post->post_title, etc.

        }
    }

    wp_reset_postdata();

} catch (Exception $ex) {
    error_log($ex);
}

但是,我什么也得不到。

有什么建议我做错了吗?

感谢您的回复!

推荐答案

$today= date('Ymd');
$args = array(
    'post_type' => 'Calendar-Events',
    'post_status' => 'publish',
    'posts_per_page' => -1,
        'meta_query' => array(
            array(
                'key' => 'ce_timestamp',
                'compare' => '>=',
                'value' => $today,
            ),
        ),

    );

$upcomingEvents= new WP_Query( $args );

试试这个

阅读全文

相关推荐

最新文章