This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('admin_init', function() { | |
global $wpdb, $sitepress; | |
$langs = 3; // set how many languages site has | |
$query = "SELECT ID, post_title, count(ID) AS cnt FROM {$wpdb->prefix}posts WHERE post_type LIKE 'attachment' GROUP BY post_title HAVING cnt > " . $langs; | |
$duplicated = $wpdb->get_results($query); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UPDATE | |
wp_posts posts | |
INNER JOIN ( | |
SELECT | |
original_id.id, | |
p_original_slug.post_name | |
FROM ( | |
SELECT | |
p.id, | |
tr.language_code, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELETE FROM | |
wp_posts | |
WHERE | |
post_type = 'attachment' | |
AND ID NOT IN( | |
SELECT | |
MIN(ID) | |
FROM ( | |
SELECT | |
ID, post_type, post_name FROM wp_posts) AS r1 |