So I was looking for a way to collate my most viewed posts from 2014 using the data available on post views provided by the plugin WP-PostViews and couldn’t figure it out. It doesn’t seem to support ordering for categories or archives although you can sort the main page by views using the URL format ?v_sortby=views&v_orderby=desc
.
So I had to write a custom MySQL query to extract the data, I could have built a WordPress query around it which would live update the list – but that’s more than I need. I just need the data to put in a post.
So here it is:
1 |
select wp_posts.post_title, wp_postmeta.meta_value from wp_posts, wp_postmeta where wp_posts.ID = wp_postmeta.post_id and wp_postmeta.meta_key = "views" and post_date between "2014-01-01" and "2014-12-31" order by ABS(wp_postmeta.meta_value) DESC; |
This query will extract all post titles and view amounts from wp_posts and wp_postmeta for 2014 and display them in one table, alter as you require.
Comments are closed.