Today a friend asked me to uninstall the Yuzo Related Post plugin from her WordPress blog because she want to switch to the Jetpack built-in “related posts” feature. She could perform the task by herself, but she also wanted to keep the post view counters for all their posts – an additional feature provided by Yuzo – which would be lost otherwise.
She found a great replacement plugin to handle the post view counting task: the awesome WP Post Views Counter: however, the new plugin doesn’t have a built-in feature to import the data collected by Yuzo.
That’s why she called me, hoping that I could be help her with such importing/transfering feature.
The first thing I did was comparing the two tables used by the plugins to host their data.
The Yuzo Related Posts table is called wp_yuzoviews and has the following structure:
|ID||int (11)||NOT NULL|
The WP Post Views table is called wp_post_views and has the following structure:
|id||bigint (20)||NOT NULL|
The main differences between the two approaches is that Yuzo Related Posts hosts a single record per post/page, while WP Post Views creates 4 records per post, each one with a different type: each record type hosts a dedicated counter so that the plugin can keep track of each post’s views for each and every day, month, year and, of course, the overall total.
Unfortunately, as we can clearly see, there’s no way to import all these detailed data from the Yuzo table, since it only keep track of the total views. The only thing I could do was transfer the total post data with the following query:
INSERT INTO wp_post_views (id,type,period,`count`)
SELECT post_id, 4, "total", views from wp_yuzoviews
ON DUPLICATE KEY UPDATE `count` = wp_yuzoviews.views;
Once done, all the usable data collected by Yuzo could be also seen by WP Post Views.