IT Blog

  • Blog
  • Technology
    • Technology
    • Architecture
    • CMS
    • CRM
    • Web
    • DotNET
    • Python
    • Database
    • BI
    • Program Language
  • Users
    • Login
    • Register
    • Forgot Password?
  • ENEN
    • 中文中文
    • ENEN
Experience IT
In a World of Technology, People Make the Difference.
  1. Home
  2. Technology
  3. CMS
  4. Wordpress
  5. Plugin
  6. Controlling posts order in plugin WP Tab Widget

Controlling posts order in plugin WP Tab Widget

2019-04-13 3347 Views 0 Like 0 Comments

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!

Table of Contents

  • Here are the facts:
  • How to reflect the real ranking
  • Note:

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)
SELECT p.id,'_wpt_view_count',t.postcount
FROM wp_pvc_total t
JOIN wp_posts p on p.id=t.postnum 
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);

Note:

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

Result:

  • 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;

Loading

error
fb-share-icon
Tweet
fb-share-icon
IT Team
Author: IT Team

Tags: Blog
Last updated:2021-01-03

IT Team

This person is lazy and left nothing

Like
< Previous
Next >

Comments

Cancel reply
Newest Hotspots Random
Newest Hotspots Random
Rich editor not working Making web page scroll down automatically Getting data from Dapper result All Unicode Chars How to keep and display contact form 7 data Common Regular Expressions
fix menu arrow String concatenation in c# and php Switch external image for index page and posts github failed to push to the remote repository. see the output window for more details Exam MB2-716 Dynamics 365 Customization and Configuration Apostrophe 2 title font is too big
Categories
  • Architecture
  • BI
  • C#
  • CSS
  • Database
  • DotNET
  • Hosting
  • HTML
  • JavaScript
  • PHP
  • Program Language
  • Python
  • Security
  • SEO
  • Technology
  • Web
  • Wordpress

COPYRIGHT © 2021 Hostlike IT Blog. All rights reserved.

This site is supported by Hostlike.com