How to display only posts from the last day with posts published?
-
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?
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘How to display only posts from the last day with posts published?’ is closed to new replies.