Title: get_posts date not working
Last modified: August 19, 2016

---

# get_posts date not working

 *  Resolved [goldmember](https://wordpress.org/support/users/goldmember/)
 * (@goldmember)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/get_posts-date-not-working/)
 * on [this page](http://onlycornerstone.com.previewdns.com/) i have the code below
   to pull in the two most recent posts. however for some reason, the date it says
   below the title is January 20, 2011 for both posts event though they both have
   two different “Published Dates” than that.
 * why’s this happening???
 *     ```
       <h2>The Latest at Cornerstone</h2>
   
       <?php
       $latestposts = get_posts('numberposts=2&category=1');
       foreach($latestposts as $post) :
          setup_postdata($post);
       ?>
       <h3><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title; ?></a></h3>
       <h6><?php the_date(); ?></h6>
       <?php the_content(); ?>
       <?php endforeach; ?>
       ```
   

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [David Calhoun](https://wordpress.org/support/users/dpcalhoun/)
 * (@dpcalhoun)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/get_posts-date-not-working/#post-1946424)
 * I would recommend using a custom loop with `query_posts()` rather than using `
   get_posts()`. You would need to limit the number of posts by using the `post_per_page`
   parameter.
    - [http://codex.wordpress.org/The_Loop](http://codex.wordpress.org/The_Loop)
    - [http://codex.wordpress.org/Function_Reference/query_posts](http://codex.wordpress.org/Function_Reference/query_posts)
 *  Thread Starter [goldmember](https://wordpress.org/support/users/goldmember/)
 * (@goldmember)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/get_posts-date-not-working/#post-1946447)
 * oy. that’s getting pretty advanced for me. whats wrong with the code i have???
   everything but the date seems to be working.
 *  [David Calhoun](https://wordpress.org/support/users/dpcalhoun/)
 * (@dpcalhoun)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/get_posts-date-not-working/#post-1946448)
 * It might be your use of `the_date()` rather than `the_time()`. Either way, try
   something like this: [http://wordpress.pastebin.com/xK5eE7Qi](http://wordpress.pastebin.com/xK5eE7Qi)
 *  Thread Starter [goldmember](https://wordpress.org/support/users/goldmember/)
 * (@goldmember)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/get_posts-date-not-working/#post-1946485)
 * that didnt work. if you look at the site now, for some reason, it’s now not restricting
   the 2 posts it shows to just those of category 1. that second post is from a 
   different category.
 * plus, i dont want the time on there, I need the date. please advise.
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/get_posts-date-not-working/#post-1946488)
 * try with this: [http://wordpress.pastebin.com/my0Wiigb](http://wordpress.pastebin.com/my0Wiigb)
 *  Thread Starter [goldmember](https://wordpress.org/support/users/goldmember/)
 * (@goldmember)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/get_posts-date-not-working/#post-1946495)
 * well that did solve the date issue. thanks. however, now the titles of those 
   posts have disappeared. you can see [here](http://onlycornerstone.com.previewdns.com/category/blog/)
   the titles of those two posts, that should be appearing on the homepage.
 * please advise.
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/get_posts-date-not-working/#post-1946497)
 * I didn’t look at the title but try it with this: [http://wordpress.pastebin.com/BqF7bjNe](http://wordpress.pastebin.com/BqF7bjNe)
 *  Thread Starter [goldmember](https://wordpress.org/support/users/goldmember/)
 * (@goldmember)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/get_posts-date-not-working/#post-1946500)
 * bingo! thanks so much!

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘get_posts date not working’ is closed to new replies.

## Tags

 * [date](https://wordpress.org/support/topic-tag/date/)
 * [get_posts](https://wordpress.org/support/topic-tag/get_posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 8 replies
 * 3 participants
 * Last reply from: [goldmember](https://wordpress.org/support/users/goldmember/)
 * Last activity: [15 years, 2 months ago](https://wordpress.org/support/topic/get_posts-date-not-working/#post-1946500)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
