//* Get post view counts
function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "0 Views";
}
return $count.' Views';
}
function setPostViews($postID) {
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
}else{
$count++;
update_post_meta($postID, $count_key, $count);
}
}
//* Prevent prefetching from adding extra views
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
add_action( 'genesis_loop', 'nabm_get_individual_post_count');
function nabm_get_individual_post_count() {
if ( is_single() ) {
setPostViews(get_the_ID());
}
}
//* Add shortcode to display counts in post meta
function nabm_post_views_shortcode() {
echo getPostViews(get_the_ID());
}
add_shortcode( 'post_views', 'nabm_post_views_shortcode' );
//*LL-Customize the entry meta in the entry header with date modified
add_filter( 'genesis_post_info', 'add_modified_date_post_info' );
function add_modified_date_post_info($post_info) {
$post_info = 'Updated: [modified_date] by [post_author_posts_link] [post_views] [post_edit]';
return $post_info;
}