显示即将发生的事件(包括今天的事件)?(Showing upcoming events (inclu

2019-10-18 07:11发布

我有以下的循环,完全不是那么回事。 我想只显示即将发生的事件,包括正在发生的事件今天。

目前,它显示了所有即将到来的职位,但也是今天的日期之前的职位。

我要去哪里错了?

    <?php 
    $today = date('Ymd');
    $portfolioloop = new WP_Query(
    array(
    'post__not_in' => array(4269),
    'paged' => get_query_var('paged'),
    'meta_key' => the_date(),
    'post_status' => 'future,publish',
    'post_type' => 'whatson',
    'exclude' => '4269',
    'posts_per_page' => 20,
    'order' => 'ASC',
    'meta_query' => array(
    array('key' => the_date(),
    'value' => $today,
    'compare' => '>=')
    ),
    )); ?>
    <?php while ( $portfolioloop->have_posts() ) : $portfolioloop->the_post(); ?>
    // content here.
    <?php endwhile; // end of the loop.  ?>

我给这个一去:

// Create a new filtering function that will add our where clause to the query
function filter_where( $where = '' ) {
    $today = date('Ymd');
    $where .= " AND post_date >= '$today' ";
    return $where;
}

add_filter( 'posts_where', 'filter_where' );
$query = new WP_Query( $query_string );
remove_filter( 'posts_where', 'filter_where' );

                <?php 
                $query = new WP_Query(
                array(
                    'post__not_in' => array(4269),
                    'paged' => get_query_var('paged'),
                    'post_type' => 'whatson',
                    'exclude' => '4269',
                    'posts_per_page' => 20,
                    'order' => 'ASC'
                )); ?>

Answer 1:

我想这可能工作:

<?php 

function filter_where( $where = '' ) {
$where .= " AND post_date >= '" . date("Y-m-d") . "'";
return $where;
}

add_filter( 'posts_where', 'filter_where' );

$query = new WP_Query(
    array(
        'post__not_in' => array(4269),
        'paged' => get_query_var('paged'),
        'post_type' => 'whatson',
        'exclude' => '4269',
        'posts_per_page' => 20,
        'order' => 'ASC'
    )
);

remove_filter( 'posts_where', 'filter_where' );
?>


文章来源: Showing upcoming events (including todays event)?
标签: php wordpress