Answer the question
In order to leave comments, you need to log in
How to exclude re-counting the number of views per IP for popular WordPress posts?
Hello. Please help me figure it out. How to exclude re-counting the number of views for popular posts from the same IP, i.e. if a person from this IP has looked at an article, then the calculation should no longer be carried out upon re-entry.
And another question is what needs to be corrected in the code for compatibility with caching plugins? In one article ( https://wpcafe.org/tutorials/kak-otobrazhat-populy... ), for compatibility with the caching plugin, the author writes the following solution, but I did not understand what exactly it changes, namely:
"We using the W3 Total Cache plugin, it has an option called Fragmented Caching, you can also use this plugin and this option to make everything work properly, here is what you need to change:
I use the following solution bloggood.ru/wordpress/kak-vyvesti-populyarnye-zapi...
in functions.php
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 ' Views: '.$count;
}
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);
}
}
in single.php to collect page view information
<?php setPostViews(get_the_ID()); ?>
Display the number of views
Answer the question
In order to leave comments, you need to log in
SELECT *
FROM `messages` m
JOIN `users` u1 ON u1.`id` = m.`fromid`
JOIN `users` u2 ON u2.`id` = m.`toid`
do a check if there are no cookies call wpb_set_post_views(get_the_ID());
then set cookies.
as I understand it, if with a caching plugin, then instead of wpb_set_post_views ($ post_id); write
this is a dynamic block https://odd.blog/2013/05/01/mfunc-in-wp-super-cach...
Delving into this topic, I read that the counter of unique views through Cookies should not be done for many reasons
https://ru.stackoverflow.com/questions/454939/%D0%...
But then how else can you implement the counter of unique views so that it can be was to link to this decision bloggood.ru/wordpress/kak-vyvesti-populyarnye-zapi...
Read www.cyberforum.ru/php-beginners/thread1626274.html, but even more questions. What is the best solution?
I will be grateful for advice!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question