0

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" 
);

1 Answer 1

2

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" 
    );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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