I want to do a query and sort posts by views. Is this possible? I'm not even sure where to start..

  • 1
    take a look at gist.github.com/2175805 – Bainternet Apr 11 '12 at 6:52
  • @Bainternet In a high traffic scenario there will be a race condition with this approach. – Brian Fegter Aug 31 '12 at 13:23
  • @BrianFegter not really but it will lose count if a simple cache plugin is in place. – Bainternet Aug 31 '12 at 16:20
  • @Bainternet A race condition will occur if more than one connections are trying to increment that postmeta at the same time. I've built one of these before for a site with millions of hits a day and it's a reality. To route the caching, we did it asynchronously combined with memcache. We then converted memcache over to postmeta at intervals. If it's a low traffic scenario, there shouldn't be an issue. – Brian Fegter Aug 31 '12 at 17:05
  • @BrianFegter That makes sense :) – Bainternet Sep 1 '12 at 10:02

WordPress does not maintain post view count by default.

But you may find the following post helpful.

Does wordpress have a post hit counter?

You may also have a look on the WP-PostViews plugin.

Many thanks.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.