Skip to content

Instantly share code, notes, and snippets.

@hampusn
Created June 11, 2015 07:39
Show Gist options
  • Save hampusn/21d316d36d38bae8c336 to your computer and use it in GitHub Desktop.
Save hampusn/21d316d36d38bae8c336 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