dfactoryplugins / post-views-counter Goto Github PK
View Code? Open in Web Editor NEWPost Views Counter
Post Views Counter
Please store all post views in post_meta (where all post meta values should be stored).
When stored this way users can run our own queries and extend them with other taxonomies and meta queries (without writing extensive wpdb queries ourself).
This is CSS output added on each page:
<style>
#wp-admin-bar-pvc-post-views .pvc-graph-container { padding-top: 6px; padding-bottom: 6px; position: relative; display: block; height: 100%; box-sizing: border-box; }
#wp-admin-bar-pvc-post-views .pvc-line-graph {
display: inline-block;
width: 1px;
margin-right: 1px;
background-color: #ccc;
vertical-align: baseline;
}
#wp-admin-bar-pvc-post-views .pvc-line-graph:hover { background-color: #eee; }
#wp-admin-bar-pvc-post-views .pvc-line-graph-0 { height: 1% }
#wp-admin-bar-pvc-post-views .pvc-line-graph-1 { height: 5% }
#wp-admin-bar-pvc-post-views .pvc-line-graph-2 { height: 10% }
#wp-admin-bar-pvc-post-views .pvc-line-graph-3 { height: 15% }
#wp-admin-bar-pvc-post-views .pvc-line-graph-4 { height: 20% }
#wp-admin-bar-pvc-post-views .pvc-line-graph-5 { height: 25% }
#wp-admin-bar-pvc-post-views .pvc-line-graph-6 { height: 30% }
#wp-admin-bar-pvc-post-views .pvc-line-graph-7 { height: 35% }
#wp-admin-bar-pvc-post-views .pvc-line-graph-8 { height: 40% }
#wp-admin-bar-pvc-post-views .pvc-line-graph-9 { height: 45% }
#wp-admin-bar-pvc-post-views .pvc-line-graph-10 { height: 50% }
#wp-admin-bar-pvc-post-views .pvc-line-graph-11 { height: 55% }
#wp-admin-bar-pvc-post-views .pvc-line-graph-12 { height: 60% }
#wp-admin-bar-pvc-post-views .pvc-line-graph-13 { height: 65% }
#wp-admin-bar-pvc-post-views .pvc-line-graph-14 { height: 70% }
#wp-admin-bar-pvc-post-views .pvc-line-graph-15 { height: 75% }
#wp-admin-bar-pvc-post-views .pvc-line-graph-16 { height: 80% }
#wp-admin-bar-pvc-post-views .pvc-line-graph-17 { height: 85% }
#wp-admin-bar-pvc-post-views .pvc-line-graph-18 { height: 90% }
#wp-admin-bar-pvc-post-views .pvc-line-graph-19 { height: 95% }
#wp-admin-bar-pvc-post-views .pvc-line-graph-20 { height: 100% }
</style>
Followed this guide: https://dfactory.eu/support/topic/exclude-stylesheet-when-not-displaying-counter-on-front-end/#post-36689
add_filter( 'pvc_enqueue_styles', '__return_false' );
It removes dashicons and frontend css file, but mentioned above inline css is still output on the page.
Hi,
I use your plugin with WP_Query, and when I use 'orderby' => 'post_views' , it only show posts with views OR posts featured (?)
Can we also show posts with 0 views ?
Stack Trace :
1. strtr()/wp-content/plugins/post-views-counter/includes/class-counter.php:795
2. Post_Views_Counter_Counter->encrypt_ip()/wp-content/plugins/post-views-counter/includes/class-counter.php:117
3. Post_Views_Counter_Counter->check_post()/wp-content/plugins/post-views-counter/includes/class-counter.php:258
4. Post_Views_Counter_Counter->check_post_rest_api()/wp-includes/rest-api/class-wp-rest-server.php:1140
5. WP_REST_Server->respond_to_request()/wp-includes/rest-api/class-wp-rest-server.php:987
6. WP_REST_Server->dispatch()/wp-includes/rest-api/class-wp-rest-server.php:414
7. WP_REST_Server->serve_request()/wp-includes/rest-api.php:370
8. rest_api_loaded()/wp-includes/class-wp-hook.php:303
9. WP_Hook->apply_filters()/wp-includes/class-wp-hook.php:327
10. WP_Hook->do_action()/wp-includes/plugin.php:518
11. do_action_ref_array()/wp-includes/class-wp.php:388
12. WP->parse_request()/wp-includes/class-wp.php:750
13. WP->main()/wp-includes/functions.php:1291
14. wp()/wp-blog-header.php:16
15. require('...')/index.php:17
16. {main}
thrown in /wp-content/plugins/post-views-counter/includes/class-counter.php on line 795
PHP Version : 8.0.6
Plugin Version : 1.3.10
Also, I noticed that view counts are stopped since this update.
Hi, at https://wordpress.org/plugins/post-views-counter/ I see the new version 1.2.9, please tell me what changes are made? hmm on git old version 1.2.8, last stable 1.2.9?
If in includes/columns.php
line 273 you write absint( $count );
for the bulk edit input, when save it, all selected post receive the first parsed post value. You must keep the input empty to populate the data whit the jQuery script.
Hello nice plugin !
It would be great to include a function who allows you to update post views of a post by its ID
Can you try to implement it ?
Thanks
Hello,
I use FastAJAX mode for counting views, and set count interval to 24 hours.
I found a strange problem, everytime I refresh the page, the post views will count once.
In includes/counter.php
check_cookie()
will be triggered by plugins_loaded
actoin and check_post($id)
will run after it receive a AJAX request
I did a small test (give each Post_Views_Counter_Counter
a random id),
it seem like these two function run on different class instances, so when check_post($id)
run, it always can't access cookie data.
I'm not sure if it is the key to cause this problem, now I simply fix this problem by adding one line $this->check_cookie();
to check_post($id)
, force it initialize cookie first.
Hi there,
I just wanted to ask if there's a way to get the views count of a post in from the WP_Post object?
Thanks
I'm working on a Headless CMS with a plugin integration of Post View Counter, there is a way to expose the number of views to GraphQL requests?
The bbPress Forum roles are not shown as options to exclude visitors.
Hi,
Thanks for the great plugin! I have an issue where I'd like to increase the views of embedded media within my post content.
I'm using the pvc_view_post
function to increase the view count but it's increasing the views every time I refresh the page content. How do I increase the view only once so it behaves the same way as viewing the attachment directly and only increases the view once (so multiple refreshes don't keep increasing the view count).
Thanks!
I've recently updated from 1.3.1
to 1.3.4
and after a while noticed all page views have been lost in the mean time. I didn't change any settings or behaviors after the update. After a closer look on the source code, it looks like some refactor was being conducted and as far as I could understand it wasn't completed but actually released.
This commit looks like where it all changed as you can see it will call a db_prepare_insert
and then db_commit_insert
instead of the former db_insert
.
Below you can check the actual method code with the important INSERT
query commented:
post-views-counter/includes/counter.php
Lines 671 to 686 in b205915
I'm not sure why it is commented or how did this get to a release without working and specially because it has been a long while it has happened and no one eventually noticed I am curious if there is actually a different way to do it after that release that I didn't catch.
P.S. Reverting to PVC 1.3.1
got it back working.
For the record, I am using WP 5.7
with nginx 1.18.0
and PHP 7.4.16
.
Below a screenshot of relevant configuration screen:
Please let me know if I can provide any further information and be helpful on improving this great plugin!
Keep Rocking!
Can I show the counter programmatically, such as get_the_author(); ?
How do I make the database smaller?
And does this option Reset Data Interval, if I use it, will it clean the database without affecting the statistics?
I want to use it with Post Pay Counter
Will the Reset Data Interval option affect the data with this addition?
Hi, you have a very cool plugin, but I have a buggy site for high traffic (4000 people per minute for example), I use counting in RAM, and I add information about views on the crown every 3 minutes, I think the problem is related to the fact, that counting views is through admin-ajax.php, because connecting this script draws a lot of dependencies of WordPress, can you add your own script for counting in order not to drag all the dependencies of WordPress, then this process would be easier? can you advise something? Thanks
Hi, will the counter with the Redis work? with memcached work fine, but I plan to switch to redis=) thanks for reply
I got this error in my console log
Uncaught TypeError: Cannot read properties of null (reading 'classList')
at Object.init (/app/plugins/cookie-…nt.js?ver=2.1.5:372)
at /app/plugins/cookie-…nt.js?ver=2.1.5:455
Occurs on front.js line 372
Currently option to set counts interval uses the cookie to manage counts interval. This is good for most of the sites, I guess. But I'm working on a site where we need to be very strict about this.
Now user can just open an incognito browser window and hit that URL. And they can bypass the counts interval thing easily.
Maybe we can add a new table where we can log user details (user_id, IP, user agent, browser etc) and before counting visit just check if that user's hit is already counted in the interval.
Also, to keep the log table small, we can set a wp cron to clear up old entries.
It was working fine with the classic editor of WordPress. When I have installed Gutenberg editor, it stopped showing the option for edit post view.
Admin cannot change the post view number after installing Gutenberg plugin.
Kindly update the plugin.
I tried to add this issue to your support forum but it failed twice, so doing it here.
Your plugin adds a cron schedule which already exists in Wordpress default, namely the daily schedule, as explained here.
By registering this, it overtakes the default "daily" schedule so now the name of your cron schedule appears on places where it's not expected (or wanted). This can be see this screenshot.
Adrotate is now linked to your cron as is the custom plugin with sd prefix. And there are more (outside of screenshot).
It is my opinion you don't need to add this daily schedule because it already exists. I have found 4 possible solutions to avoid this. 3 are on the plugin side and 1 is on the user side.
if ( ! array_key_exists( 'daily', wp_cron_schedules() ) ) {
// add your schedule
}
public function change_cron_time_intervals( $schedules ) {
unset( $schedules['post_views_counter_interval'] );
$schedules['post_views_counter_interval'] = array(
'interval' => 86401,
'display' => __( 'Post Views Counter reset daily counts interval', 'post-views-counter' )
);
return $schedules;
}
Hi,
Awesome code! Thanks!
I was wondering, do you have a PHP function available to retrieve the pageviews for a specific post ID in PHP? So I can integrate your plugin with other plugins?
And if yes, how can I best test your plugin is active?
Looking forward to your reply. Thanks!
I've found this plugin really helpful. Thanks for making this awesome plugin. I've got a question for this plugin for integrating GA.
Or is there already tutorial or guide for this?
Thanks.
Hi.
I was implementing new third party cookie banner integration to our wordpress blog and after searching through the source code, I noticed I can easily integrate it with your plugin, however it is documented only in your other repo about function cn_cookies_accepted
. Could you please include this possible integration into this readme as well?
Thank you
Can we add number of view to REST API
wp-json/wp/v2/posts
Does the plugin support wordpress multisite? thanks for reply
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.