Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- $issues = array();
- $i = 0;
- foreach ($duplicated as $duplicat) {
- $trid = $sitepress->get_element_trid($duplicat->ID, 'post_attachment');
- if (!$trid) {
- continue;
- }
- $translations = $sitepress->get_element_translations($trid, 'post_attachment' );
- if (count($translations) < 1) {
- continue;
- }
- foreach ($translations as $lang => $tr) {
- $issues[$i]['notin'][] = $tr->element_id;
- }
- $issues[$i]['post_title'] = $duplicat->post_title;
- $i++;
- }
- foreach ($issues as $issue) {
- $notin = implode(",", $issue['notin']);
- $query = "DELETE FROM {$wpdb->prefix}posts WHERE `ID` NOT IN ($notin) AND `post_title` LIKE '" . $issue['post_title'] . "' AND `post_type` LIKE 'attachment'";
- $result = $wpdb->query($query);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement