Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

$recent_posts[0]["post_title"]

How can I get the date the post was published?

share|improve this question

1 Answer 1

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'];
endforeach;

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
1  
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

 
discard

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.