Title: Help with using NOW()
Last modified: August 18, 2016

---

# Help with using NOW()

 *  [bboldb](https://wordpress.org/support/users/bboldb/)
 * (@bboldb)
 * [19 years, 10 months ago](https://wordpress.org/support/topic/help-with-using-now/)
 * Hi, These forums are great. I’ve searched thoroughly and using code I found on
   these pages implemented a random post on my “home” page.
 * I have 2 posts “in the loop” and then the random post. I want to have the random
   post NOT be the same as either of the previous two. Say, have the random one 
   be older than 7 days.
 * I’ve done this:
 * <?php
    $rand_id = $wpdb->get_var(“SELECT ID FROM $wpdb->posts WHERE post_status
   = ‘publish’and post_date < NOW() ORDER BY RAND() LIMIT 1”); query_posts(“p=$rand_id”);?
   >
 * I think the < NOW() keeps the post from being from today. But how do I change
   it so the post is AT LEAST 7 days old OR MORE?
 * Thanks in advance,
    bboldb

Viewing 1 replies (of 1 total)

 *  Thread Starter [bboldb](https://wordpress.org/support/users/bboldb/)
 * (@bboldb)
 * [19 years, 9 months ago](https://wordpress.org/support/topic/help-with-using-now/#post-422118)
 * Okay, I think I figured it out.
 * I adapted this code presented here straight from [http://codex.wordpress.org/The_Loop](http://codex.wordpress.org/The_Loop)
 * Step 2. The second loop, get the X latest posts (except one).
 * The following code gets X recent posts (as defined in WordPress preferences) 
   save the one already displayed from the first loop and displays them according
   to Do stuff.
 *  <?php if (have_posts()) : while (have_posts()) : the_post();
    if( $post->ID 
   == $do_not_duplicate ) continue; update_post_caches($posts); ?> <!– Do stuff…–
   > <?php endwhile; endif; ?> ——————————————–
 * This will keep the random post from being the same as at least one other from
   the loop. *I think*
 * I wonder why no one wants to help me?
 * Maybe this will help someone else….

Viewing 1 replies (of 1 total)

The topic ‘Help with using NOW()’ is closed to new replies.

## Tags

 * [now](https://wordpress.org/support/topic-tag/now/)
 * [time](https://wordpress.org/support/topic-tag/time/)

 * 1 reply
 * 1 participant
 * Last reply from: [bboldb](https://wordpress.org/support/users/bboldb/)
 * Last activity: [19 years, 9 months ago](https://wordpress.org/support/topic/help-with-using-now/#post-422118)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
