Skip to content

Instantly share code, notes, and snippets.

@lusareal
Forked from hampusn/wpml-detach-duplicates.sql
Created February 25, 2019 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lusareal/f3bcbc59b4726c95daabdd89bbcb0a19 to your computer and use it in GitHub Desktop.
Save lusareal/f3bcbc59b4726c95daabdd89bbcb0a19 to your computer and use it in GitHub Desktop.
SQL queries to detach WPML duplicates and translate them separately.
# Select all posts which are duplicates of a language.
# The language parameter is to only select by the new language (not the original duplication language).
SET @lang_code = 'da';
SELECT pm.*, p.post_title, p.post_type, icl.language_code
FROM wp_postmeta pm
INNER JOIN wp_icl_translations icl ON icl.element_id = pm.post_id
INNER JOIN wp_posts p ON p.`ID` = pm.post_id
WHERE meta_key='_icl_lang_duplicate_of' AND icl.language_code = @lang_code;
# Same as above but to delete instead of select. The above should be used first to
# make sure that you don't delete the wrong rows ;)
SET @lang_code = 'da';
DELETE pm
FROM wp_postmeta pm
INNER JOIN wp_icl_translations icl ON icl.element_id = pm.post_id
WHERE meta_key='_icl_lang_duplicate_of' AND icl.language_code = @lang_code;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment