php - How to get most visited posts of the week? -
whenever user visits post, have simple function triggers adds +1 single custom field visit counter field post.
this means can visited posts of time using new wp_query()
using meta value sort, can't life of me figure out way visited posts last x days.
as i'm increasing custom field of each post 1, understand there no reference dates or anything, can't imagine coding solution make happen.
is there wordpress way determine how many times custom field changed on last 7 days?
a solution have counter per-day.
say have counter today - let's call 09052016
, , 1 tomorrow called 10052016
. views on last 7 days, take last 7 days' counters , add them together.
an easier solution possibly name these incrementally, have 000001
, 000002
, 000003
, forth.
this make lot easier write php function allow take 000182 , previous 6 counters.
ranking top posts on last 7 days possible calculating value of values:
x + (x-1) + (x-2) + (x-3) + (x-4) + (x-5) + (x-6)
i not sure whether or not efficient solution.
you have counter per day , counter per week, after 1 day subtracts amount of views day 6 days back.
Comments
Post a Comment