Website Scripts And Cloud Tutorials

How to import GD star rating to YASR plugin in WordPress

Byadmin

Feb 14, 2022
How to migrate GD star rating to YASR plugin in WordPress
Click to rate this tutorial!
[Total: 1 Average: 5]

In this tutorial I am going to show you how to easily import / migrate your rating system from GD star rating WordPress plugin to Yet Another Star Rating (YASR). Its been a while I have been thinking of migrating to YASR from GD Star rating however realized the hard truth that there was no straightforward way to do it. GD Star Rating was configured in my website for more than a decade and didn’t want to start a whole new rating system without having the historical rating data. Using this technique below I migrated more than 3K ratings to YASR. Hope some of you might find this tutorial helpful. Let us get started,

Note: The voting type we are going to copy from GD star rating is ‘article

Reason for migration

1] Export option in GD star rating is not working as expected
2] I am not finding a nice way to import data.It was just exporting couple of the post not all for some reason.
3] GD star has started showing lot of errors lately and it was no longer working. ie, when user click on the stars ratings were never saved
4] Always wanted to move to a lightweight rating system

Prerequisites

  • Make sure that you have access to the database running WordPress
  • The user accessing the database should have proper read / write permissions
  • You have the ability to take backup of the MySQL database
  • Have expertise in running MySQL queries
  • Best way to run query is using some interface like PHPMyAdmin, Check out this tutorial on how to install / configure PHPMyAdmin

YASR database table investigation

1] I figured out that yasr_log, the table name will be similar <something>_yasr_log, something=starting of the table you have given while configuring WordPress will get updated when a rating is given by the user.
2] It has mainly 5 columns post_id , user_id, vote, date and ip

post_id will be the original post id that you have
user_id is the id of the user for example normally 0 will be anonymous user and 1 will be admin
vote is nothing but the vote for that particular post, it will be 5.0, 4.0 etc., depending on the rating
date self explanatory, date in which specific post received a rating
ip IP address of the user that made the rating.

Now flipping on to the GD Star table, Similar to YASR there is a table with the name gdsr_votes_log (like above the table name will be similar _gdsr_votes_log).
You can see that table is pretty huge and has lot of columns. The main columns we have to focus on are
1] id
2] vote
3] voted
4] ip
5] vote_type

Note: In this tutorial we are only going to pull data from column “vote_type” in gd star rating with the value “article”. There are other vote types like ‘artthumb‘ , ‘cmmthumb‘ etc., I am not using them in this as I am unsure whether YASR have an option for customer comments rating. (May be its available but outside the scope of this tutorial)

How to copy the rating data?

1] Take a backup of your database (ALWAYS), we are not touching any other table other than YASR but just in case. We don’t need any surprises(Best practice approach). Recommendation from me is to take a back up of your database and then proceed. If you are unable to take backup stop here.
2] In GD star rating I was using 10 star option. Hence I decided to run the below query that automatically create stars rating compatible with YASR , for example if a post has 10 or 9 rating in GD star then it will be converted to 5 star equivalent in YARS. (Feel free to modify the query according to your requirement). My table name for YASR is wordpress_yasr_log and GD star wordpress_gdsr_votes_log

INSERT INTO wordpress_yasr_log
(post_id, vote, date,user_id,ip)
select id,
(
CASE
WHEN vote <= '10' && vote >= '9' THEN 5.0
WHEN vote <= '8' && vote >= '7' THEN 4.0
WHEN vote <= '6' && vote >= '5' THEN 3.0
WHEN vote <= '4' && vote >= '3' THEN 2.0
WHEN vote <= '2' && vote >= '1' THEN 1.0
END) AS vote,voted,user_id,ip
from wordpress_gdsr_votes_log WHERE vote_type='article';

3] As you can see I am adding a case statement in my query that get the original rating from GD star rating system and convert it to the rating YASR requires. .
the vote column in yasr_log is a decimal number so keep that in mind while adding the conversion logic.

4] Awesome!! Assuming that you have not got any errors thrown from the query you are all set. Login to the admin section and go to https://your_website/wp-admin/admin.php?page=yasr_stats_page to see the migrated ratings.

5] Make sure everything looks good and now disable the GD star plugin.

6] Keep it running for couple of days/weeks and once you are confident that YASR is working as expected, delete (recommended)the GD star plugin.

Click to rate this tutorial!
[Total: 1 Average: 5]

Leave a Reply

Your email address will not be published.