Get all post meta data

The post meta data section is typically featured in two areas on your blog post: under the post title or below the post content. The post meta data featured under the post title usually consists of the author, date and post categories and/or tags. The post meta data set below the post content may include that information along with the date the post was updated, tags, mood, location, related posts, related tags, author bios, and more.

 

 

Adding this PHP code to your wordpress functions.php will return all meta data for a single post.

 

function get_post_meta_all($post_id){
global $wpdb;
$data   =   array();
$wpdb->query("
SELECT `meta_key`, `meta_value`
FROM $wpdb->postmeta
WHERE `post_id` = $post_id
");
foreach($wpdb->last_result as $k => $v){
$data[$v->meta_key] =   $v->meta_value;
};
return $data;
}

Be Sociable, Share!

Leave a comment