WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

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.