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?
date_query
, where you've got'day' => $last_date
, do you mean'day' => $current_day
? (And why are you setting$current_year
and$current_month
if you're not using them?)