Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using the Delicacy theme. I want to show n my homepage the posts of the current day.
But if there are no post for that day it shows "No found". I want to show posts from the last day with posts instead. How can I do that?

I am using this query:

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

share|improve this question

1 Answer 1

You need to find the most recent date with posts and use that to construct the $current_ fields.

$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);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.