Hello,sorry for starting another post,here is the link of my previous similar post my previous question.Problem is when someone visit some post,I want to record that,to increment counter for that post.But counter is also increment for previous post(always previous post).Can not find a way to solve this.
here is the code that I use :
function IncrementPostCount(){
if(is_single()){
global $wp_query;
$count = get_post_meta( $wp_query->post->ID, 'readnTimes', true );
$count = empty($count) ? 1 : $count + 1;
add_post_meta($wp_query->post->ID, 'readnTimes', $count, true) or update_post_meta($wp_query->post->ID, 'readnTimes', $count);
}
}
add_action( 'template_redirect', 'IncrementPostCount' );
Can someone help me with this please.