Controlling posts order in plugin WP Tab Widget

Controlling posts order in plugin WP Tab Widget

The plugin “WP Tab Widget” is great widget to display popular posts and recent posts on the sidebar. However, once you installed it you would soon find out that it displays the result with non-sense!

Here are the facts:

  • the plugin pick posts randomly, and adds meta_key/value pairs into wp_postmeta table with 2 digits number, as ranking values;
  • the larger meta_value the higher display position on the widget;
  • the actual views of a post do not change the ranking position (do not change the meta_value);
  • actually, the plugin allows you to control the post position displayed in the widget by yourself. You need to manually enter the meta_value of a post into wp_postmeta table, in order to control the display order in the widget.

How to reflect the real ranking

In order to reflect the real ranking we need to get help with other plugin called Page Views Count. This plugin count every user visit on posts.

Run the following script periodically, e.g. daily, hourly.

DELETE FROM wp_postmeta WHERE meta_key='_wpt_view_count';

INSERT INTO wp_postmeta (post_id,meta_key,meta_value)
FROM wp_pvc_total t
JOIN wp_posts p on 
WHERE p.post_type='post' and p.post_status='publish'
order by postcount DESC limit 20;

-- if you have specific post need to be placed in the first position, run the following
delete from wp_postmeta WHERE post_id=6668 and meta_key='_wpt_view_count';
INSERT INTO wp_postmeta (post_id,meta_key,meta_value) VALUES (6668,'_wpt_view_count',99999);


  • To query the order of the posts in the widget, run this query:
SELECT,p.post_title,m.meta_value `read` FROM wp_postmeta m
JOIN wp_posts p ON
WHERE meta_key='_wpt_view_count'
ORDER BY CAST(m.meta_value as signed) DESC


  • Using the following script to control the post order in the widget:
INSERT INTO wp_postmeta (post_id,meta_key,meta_value) VALUES (@post_id, '_wpt_view_count',@ranking);

or just update the meta_value for the post if the record already exists:

UPDATE wp_postmeta set meta_value=55 where meta_key='_wpt_view_count' and post_id=@post_id;

 2,850 total views

Author: Albert

Leave a Reply