WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Query post by date (3 posts)

  1. ecsancho
    Member
    Posted 1 year ago #

    Greetings!

    I was wondering how I can query post by date? I need to check if there's any post made yesterday and respond accordingly. When use have_posts() and in any page thats not index the return results are not consistent for what I need it to do.

    Much thanks!

  2. http://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters

    example:

    $yesterday = getdate( strtotime('-1 day', strtotime("12:00:00") ) );
    $query = new WP_Query( 'year=' . $yesterday["year"] . '&monthnum=' . $yesterday["mon"] . '&day=' . $yesterday["mday"] );
    if( $query->have_posts() ) :
    //there are posts from yesterday//
    endif;
  3. ecsancho
    Member
    Posted 1 year ago #

    Super helpful! Super Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic