ShoutMeLoud

SQL Query To Move Meta_Value From One Meta_Key To Another

Recently I moved my SEO settings from theme to SEO by Yoast plugin, and thanks to Data transporter plugin made the job easier. One of the underlooked feature of SEO by Yoast plugin is Social SEO feature, in which you can define the different title for Facebook, Google Plus, Twitter & more.

For long, I was using WP Social SEO (Which is a paid plugin), and after switching to the Yoast SEO plugin, it was no longer necessary to stick to old plugin.

The issue that I faced is, I had to move all my database value from old plugin to SEO by Yoast. This process required:

  • Import old value from one database table to table created by SEO by Yoast plugin

I tried many SQL queries to get this accomplished, and after a few failed trial I managed to find the right SQL query for the same. If you are stuck with your old SEO plugin or want to move meta_value of one meta_key to another, here is the command for you.

Note: Before you run this command, ensure you take the backup of your database. I take no responsibility for any mishap.

For me, below SQL query worked & I managed to transfer all values from old Social SEO plugin to SEO by Yoast Social SEO tables.
UPDATE `dbname`.`wp_sndr2f_postmeta`
SET meta_key = '_yoast_wpseo_opengraph-title'
WHERE meta_key = '_wps_seo_booster_ogp_title'

In the above SQL query:

  • _yoast_wpseo_opengraph-title is the open graph title meta_name for Yoast SEO plugin
  • Where as _wps_seo_booster_ogp_title have the value from old plugin.
  • dbname: replace DB name with the actual Db name

With the above query, meta_value of _wps_seo_booster_ogp_title for every post is updated to _yoast_wpseo_opengraph-title

Similarly, I had to find meta_key name for my old plugin table & using the above SQL query, migrated the meta_value to the new meta_key

Note: Make sure to replace the DB name & table name according to your database. You also need to verify that meta_value has been moved from one meta_key to another manually or by searching for value using SQL search operator.

Once you have verified that value has been migrated from old SQL key to new, you can disable the old WordPress plugin. If for any reason above  SQL query doesn’t work for you, you should restore database backup & search for the alternate SQL query.

If you have followed an alternate method to transfer data of one meta_key to another existing meta_key, do share it with me in comment section.