Skip to content

Instantly share code, notes, and snippets.

@yoanmarchal
Last active October 13, 2015 05:37
Show Gist options
  • Save yoanmarchal/4147208 to your computer and use it in GitHub Desktop.
Save yoanmarchal/4147208 to your computer and use it in GitHub Desktop.
récupère stock "dans une meta" et montre le nombre de vue par page
//recupere et stock dans une balise meta le nombre de vue par page
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 "<p>0 Visite</p>";
}
return $count.' Visites</br>';
}
//montre le nombre de vue par page
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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment