• Resolved teriyakiburger

    (@teriyakiburger)


    Thanks to this article, we were able to implement the ability to sort by number of views.

    https://www.ads-software.com/support/topic/how-to-sorting-a-custom-query-by-views-all-time-monthly-weekly-or-daily/

    However, this method is not in the order of the Most viewed tab on the stats page.
    This is because the meta field values are only updated when the page is viewed, and the meta field values for pages that have not been viewed for a long time will remain the same.

    Example:
    If a page with a ‘views_daily’ value of 5 is not viewed by anyone for 24 hours, the value will remain 5 after 24 hours.

    The solution is to periodically update the meta field for all articles. However, this is not practical if there are many pages.

    It is not a bad idea to specify a time period in the query. It won’t be the same as the stats page, but it is easier.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    The Stats page queries the database directly, hence why it can list popular posts in a dynamic way (as in it knows what the current date is and queries the database for data accordingly).

    To achieve the same effect with the WP_Query class (which I suppose is what you’re using in your project) you’d need to update your code so it “resets” these fields on a daily basis as well, there’s no way around it.

    Alternatively you may also consider using a different solution. The WP_Query approach as described on that link you shared -and as you already noticed- has this kind of limitations.

    In case it’s not obvious, I didn’t write that tutorial. It was the contribution of another user, I just updated it as there were a couple of issues with the original post and I kept getting support requests about it.

    Thread Starter teriyakiburger

    (@teriyakiburger)

    I see that there is no easy way to achieve the same effect with the WP_Query class.
    Still, this sorting feature works well enough and is great.
    Thanks for the support.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘A Better Way to Sort’ is closed to new replies.