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:
<?php
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?
get_post()
function that is native and more reliable way to retrieve single post's data.get_post()
or evenget_posts()
withposts_per_page
set to 1 andnopaging
set to true (it offers a little more than the singular counterpart).