Title: Retrieving post_date in nested loop
Last modified: August 19, 2016

---

# Retrieving post_date in nested loop

 *  [quinn_](https://wordpress.org/support/users/quinn_/)
 * (@quinn_)
 * [18 years, 2 months ago](https://wordpress.org/support/topic/retrieving-post_date-in-nested-loop/)
 * I’m a WP Newbie, and as such have not had much experience with PHP and SQL (so
   go easy on me if it’s an easy question).
 * On single.php I would like to display a second post from a different category
   that was posted on the same day. Here’s an example: The Original post was posted
   March 18, 2008. If a post from category “cake” was posted on March 18, 2008, 
   display it:
 * Here is what I have so far:
 *     ```
       <?php $dateOfOriginal = $post->post_date = date("Y m d",strtotime($post->post_date));
   
       query_posts('cat=' . $cake); while(have_posts()) : the_post();
   
         if ( $posts ) : foreach ( $posts as $post ) : start_wp();
   
           $dateOfPostInCake = $post->post_date = date("Y m d",strtotime($post->post_date)); 
   
           if($dateOfPostInCake == $dateOfOriginal) {
             the_post();
           } else {
             _e('');
           }
   
         endforeach; else:
   
           _e(''); 
   
         endif;
   
       endwhile; ?>
       ```
   
 * The first post_date query works fine, but the second one does not (it defaults
   back to “1969 12 31”). I’m assuming it has something to do with being inside 
   of a nested loop. Any ideas on how to make it work? Thanks!

The topic ‘Retrieving post_date in nested loop’ is closed to new replies.

## Tags

 * [?cat](https://wordpress.org/support/topic-tag/cat/)
 * [category](https://wordpress.org/support/topic-tag/category/)
 * [date](https://wordpress.org/support/topic-tag/date/)
 * [display](https://wordpress.org/support/topic-tag/display/)
 * [else](https://wordpress.org/support/topic-tag/else/)
 * [foreach](https://wordpress.org/support/topic-tag/foreach/)
 * [have_post](https://wordpress.org/support/topic-tag/have_post/)
 * [if](https://wordpress.org/support/topic-tag/if/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [page](https://wordpress.org/support/topic-tag/page/)
 * [post](https://wordpress.org/support/topic-tag/post/)
 * [post_date](https://wordpress.org/support/topic-tag/post_date/)
 * [query](https://wordpress.org/support/topic-tag/query/)
 * [query_post](https://wordpress.org/support/topic-tag/query_post/)
 * [retrieve](https://wordpress.org/support/topic-tag/retrieve/)
 * [single](https://wordpress.org/support/topic-tag/single/)
 * [single.php](https://wordpress.org/support/topic-tag/single-php/)
 * [the_post()](https://wordpress.org/support/topic-tag/the_post/)
 * [while](https://wordpress.org/support/topic-tag/while/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [quinn_](https://wordpress.org/support/users/quinn_/)
 * Last activity: [18 years, 2 months ago](https://wordpress.org/support/topic/retrieving-post_date-in-nested-loop/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
