Skip to content

Instantly share code, notes, and snippets.

@raank
Created October 25, 2014 22:33
Show Gist options
  • Save raank/e4d50f8395a748ab5b4c to your computer and use it in GitHub Desktop.
Save raank/e4d50f8395a748ab5b4c to your computer and use it in GitHub Desktop.
Wordpress post view counts
<?php
function get_post_views( $postID ){
$count_key = "post_views";
$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 View";
}
return $count." Visualizações";
}
function set_post_views( $postID ) {
$count_key = "post_views";
$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 );
}
}
remove_action( "wp_head", "adjacent_posts_rel_link_wp_head", 10, 0);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment