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

Is there a way of getting all posts published on the latest date? It might not necessarily be today, it might be yesterday or the day before yesterday or even a day last week.

share|improve this question

You can do it like this:

if ( have_posts() ) :
    /* Queue the first post, that way we know
     * which date we're dealing with.
     * We reset this later so we can run the loop
     * properly with a call to rewind_posts().

    // receive the latest post timestamp
    $latest_post_timestamp = strtotime( get_post()->post_date );

    /* Since we called the_post() above, we need to
     * rewind the loop back to the beginning that way
     * we can run the loop properly, in full.

    // create our custom query and set our latest date arguments
    $the_query = new WP_Query( array(
        'year' => date( 'Y', $latest_post_timestamp ),
        'monthnum' => date( 'm', $latest_post_timestamp ),
        'day' => date( 'd', $latest_post_timestamp ),
    ) );

    // render our latest date posts
    echo '<ul>';
    while ( $the_query->have_posts() ) :
        echo '<li>' . get_the_title() . '</li>';
    echo '</ul>';

    // Restore original query and post data
share|improve this answer
Plausible solution, but I think I'd run something similar on the pre_get_posts hook to reduce a little bit of overhead. – s_ha_dum Jan 14 '13 at 16:51
Works great. Thanks! – Meshi Jan 15 '13 at 14:10
@Meshi then mark the answer as accepted by clicking on the tick under votes! – Eugene Manuilov Jan 15 '13 at 15:15

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.