WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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'm using this function to be able to retrieve several data, from outside the Loop:

function get_post_data($postId) {
 global $wpdb;
 return $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE ID=$postId");

... and then, this to display the date a post was published:

global $wp_query;
global $thePostID;
$thePostID = $wp_query->post->ID;
$data = get_post_data($thePostID);
echo $data[0]->post_date;

wich displays something like "2010-06-14 22:36:03" in my sidebar, but I'd like to format it like just "June, 2010"

Can it be done?

share|improve this question
Not related to your question, but check out get_post() function that is native and more reliable way to retrieve single post's data. – Rarst Nov 17 '10 at 10:42
Agree with Rarst, why create a function for it when one exists already.. use get_post() or even get_posts() with posts_per_page set to 1 and nopaging set to true (it offers a little more than the singular counterpart). – t31os Nov 17 '10 at 15:10
up vote 7 down vote accepted

I'm using something like this:

date('F, Y', strtotime($data[0]->post_date));
share|improve this answer
Thanks!To clarify for the readers, it worked when "echoed" it – Sergio Majluf Nov 17 '10 at 4:56

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.