WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I get the latest posts this way:

$args = array( 'numberposts' => '2' );
$recent_posts = wp_get_recent_posts( $args );

Then I loop through them and get information about the post this way:


How can I get the date the post was published?

share|improve this question
up vote 2 down vote accepted

You can see everything returned via php's var_dump or print_r:

$recent_posts = wp_get_recent_posts();
echo '<pre>';
print_r( $recent_posts );
echo '</pre>';

This will reveal that the date is stored in post_date:

foreach( $recent_posts as $recent ):
    echo $recent['post_date'];

Or to format the date, use php's date and strtotime:

echo date( 'l F jS', strtotime( $recent['post_date'] ) );
share|improve this answer
There is one more thing though, it's displaying the date in enlgish even though the wp is configured in spanish (using the .mo file and the WPLANG variable). – Trufa Feb 11 '13 at 0:09
Should I take this advice? codex.wordpress.org/… Seems like a hack more than a solution – Trufa Feb 11 '13 at 0:18
you can use php's setlocale for date output in spanish, or WordPress's translation facilities that you have linked. what do you mean by not working on your server? how is it not working? – Milo Feb 11 '13 at 0:33
sorry for that, the cache plugin got me confused! I was coming back to delete the comments because I had figured it out! thanks for all the help! – Trufa Feb 11 '13 at 0:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.