0

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?

1 Answer 1

4

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'] ) );
4
  • 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
    Commented Feb 11, 2013 at 0:09
  • Should I take this advice? codex.wordpress.org/… Seems like a hack more than a solution
    – Trufa
    Commented Feb 11, 2013 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
    Commented Feb 11, 2013 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
    Commented Feb 11, 2013 at 0:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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