Take the 2-minute tour ×
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');
$current_day=date('d');

query_posts( 
    "cat=5&year=$current_year&monthnum=$current_month&day=$current_day&order=ASC" 
);
share|improve this question
add comment

1 Answer

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);
    query_posts( 
        "cat=5&year=$current_year&monthnum=$current_month&day=$current_day&order=ASC" 
    );
}
share|improve this answer
add comment

Your Answer

 
discard

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.