Is there a way to do this?

I created a Blog widgets that adds a new custom post called CustomBlogPost, and I don't see a way to do a page count aside creating a new widget and then creating a new table and then incrementing a counter for each page for every Ajax Request sent to function.php and then have a hook that increments the page from the Ajax Call.

However, this would cause performance issue, because you would have to do 2 GET and a POST for every page Visit, or 1 GET and an additional SQL request and a POST for every single visit, which would undermine performance.

Is there a better way?

  • What a can of worms - I've started writing an answer but there are so many caveats...
    – Bysander
    Jan 12 at 17:25
  • Essence is: 1. New separate table 2. Ajax call on the page footer 3. Write page ID as new entries to new table to count later. 4. Cron job to count, then write it into post_meta or something cacheable - clear the table as part of this cron. Note: Live up-to-date page views aren't recommended and contain a lot of overhead. Services like Adobe or Google might be better to log these from you, then you can update your stored page-views with an API call every 20-30 mins.
    – Bysander
    Jan 12 at 17:40


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.