WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Posts within the last 7 days (3 posts)

  1. drmike
    Member
    Posted 7 years ago #

    Greets:

    I'm trying to figure out a mthod of displaying the posts created within the last x amount of days. I gather that this doesn't work:

    $dt_start = mktime(0, 0, 0, date("n"), date("j"), date("Y"));
    $dt_recent = $dt_start - 604800;
    
    $query2  = "SELECT * FROM wp_posts WHERE $dt_recent <= strtotime('post_date_gmt') ORDER BY ID";

    Suggestions?

    Thanks,
    -drmike

  2. pizdin_dim
    Member
    Posted 7 years ago #

    Try using the MySQL "datediff()" function instead. Something like this should work:

    select * from posts where datediff(now(), post_date) < 8;

  3. drmike
    Member
    Posted 7 years ago #

    Looks like that'll work.

    Thanks,
    -drmike

Topic Closed

This topic has been closed to new replies.

About this Topic