admin管理员组

文章数量:1124750

The goal is to show today's published posts or, if there's none, the last day's with posts published posts.

I found this old question, but the code suggested uses query_posts. I'd like to use WP_Query. I tried to scramble something, but it didn't work:

    $current_year = date('Y');
    $current_month = date('m');
    $current_day=date('d');

    $today = getdate();
    $last_date = $wpdb->get_var("SELECT DATE(MAX(post_date)) FROM {$wpdb->posts} LIMIT 1");
    if (!empty($last_date)) {
    list($current_year,$current_month,$current_day) = explode('-',$last_date);
   } 

    $args = array(
        'date_query' => array(
            array(
                'after'     => array(
                    'year'  => $today["year"],
                    'month' => $today["month"],
                    'day'   => $last_date,
                ),
                'inclusive' => true,
            ),
        ),
        'posts_per_page' => -1,
    );

Any idea what's wrong?

本文标签: wp queryHow to display only posts from the last day with posts published