Display post views within admin post columns

I posted a cool snippet yesterday to (track post views using post meta) I wanted to add a little to that today. Adding this snippet to the functions.php of your wordpress theme will display the post views next to each post in the wordpress admin.

 

 

 

add_filter('manage_posts_columns', 'posts_column_views');
add_action('manage_posts_custom_column', 'posts_custom_column_views',5,2);
function posts_column_views($defaults){
$defaults['post_views'] = __('Views');
return $defaults;
}
function posts_custom_column_views($column_name, $id){
if($column_name === 'post_views'){
echo getPostViews(get_the_ID());
}
}

Be Sociable, Share!

Leave a comment