Yes, but did you try editing this in the edit post screen on the admin side? PVC adds a new field to publish metabox where you can do that with ease for each post separately.
Regards
Bartosz / dfactory
Yes I know about editing it on the admin side but I would like to do it with PHP & Javascript as I want to attach it to the links the users click on.
For example, I have a RSS aggregator website. Each time the user click on the links that exits the website, I would like to manually add 1 view to the post that relates to the link. [I would like to attach a Javascript code to this]
Another would be me providing RSS feeds to my user. Example link: http://www.mysite.com/ext/34305/. When users click on that link, i would like to add a view to the post that relates to that link. [I would like to do this in PHP]
As you can see, when users click on the link, it won’t go to the post but actually exit the website. The links is related to the post so I would like to add a view to the post ID.
I would just like to know if there’s a function or way to easily add views to a post id via PHP and Javascript code. Thanks!
These are good questions actually.
There is no out of the box mothod for this now. But we could provide one – just wondering how to do that in a flexible way.
One word about how it works: both PHP and JS modes fire similar (but not exactly the same) functions that first does multiple checks on whether the view should be counted or not. Then, if all the conditions are met (the viewer is not a robot, nor a logged out user, etc. depending on your settings) the cookie is being stored, and the counting function is fired, that performs the db query and handles object cache (if you have it enabled).
Now where would be the best point / moment for this? From what I think it would be just before or after saving the cookie to the browser. We could provide an action hook (one or more) here.
What you think?
From what I think it would be just before or after saving the cookie to the browser
Honestly, I’m not sure what’s the best way to do this as my programming skills aren’t that great. Whatever you decide would work best 🙂
Thanks for listening to my request!
I’m looking for this option, too. Using WP REST API to retrieve all post data. On this site WordPress doesn’t handle rendering views at all, and therefore no view is logged. I need a way to log a view every time the article endpoint is hit.