cabrerahector / wordpress-popular-posts

WordPress Popular Posts - A highly customizable WordPress widget that displays your most popular posts.
https://wordpress.org/plugins/wordpress-popular-posts/
GNU General Public License v2.0
280 stars 82 forks source link

Multiply hits #333

Closed blacknightt1 closed 2 years ago

blacknightt1 commented 2 years ago

Hi again I want to change the number of hits from 1 to 4 For example, with each visit of each post, it should be calculated 4 times, not 1 times

cabrerahector commented 2 years ago

Hi @blacknightt1,

Currently there's no way to do this, at least not without making changes to the plugin. You'll either need to wait for me to add a solution that allows this or you'll have to modify the plugin yourself if you need this kind of functionality right away.

blacknightt1 commented 2 years ago

I'm satisfied with this plugin, just add this item to the plugin thank you

cabrerahector commented 2 years ago

Hi @blacknightt1,

Alright so I just added a new filter hook to the plugin called wpp_update_views_count_value that will allow you to change the views count of a post (a.k.a. "hits" that gets saved to the database when someone visits a post or a page (or a custom post type).

In your specific case, you'd need to add this code snippet to your theme's functions.php file (or to a site-specific plugin) to have WordPress Popular Posts "multiply" the views count by 4:

add_filter( 'wpp_update_views_count_value', function($views, $post_ID, $sampling, $sampling_rate) {
    return 4;
}, 10, 4);

Note that this filter hook is available only from plugin version 6.0.0 (which will be released officially soon) and on.