Last active
October 2, 2015 18:38
-
-
Save alexpirine/2296581 to your computer and use it in GitHub Desktop.
Deletes postmeta duplicates
This file contains 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 | |
# Copyright Alexandre Syenchuk, 2012 | |
# a multi-site, multi-duplicates version of https://gist.github.com/1177018 | |
header('Content-type: text/plain; charset=utf-8'); | |
include('wp-config.php'); | |
include('wp-load.php'); | |
global $wpdb; | |
$req_tpl = <<<eof | |
DELETE FROM %s | |
WHERE meta_key = '_mf_write_panel_id' | |
AND post_id IN (SELECT * FROM ( | |
SELECT post_id | |
FROM %s | |
WHERE meta_key = '_mf_write_panel_id' | |
GROUP BY post_id | |
HAVING COUNT(post_id) > 1 | |
) AS tmp1) | |
AND meta_id NOT IN (SELECT * FROM ( | |
SELECT meta_id | |
FROM %s | |
WHERE meta_key = '_mf_write_panel_id' | |
GROUP BY post_id | |
HAVING COUNT(post_id) > 1 | |
) AS tmp2) | |
; | |
eof; | |
$blogs = $wpdb->get_results("SELECT blog_id FROM $wpdb->blogs"); | |
foreach ($blogs as $blog) | |
{ | |
$blog_id = $blog->blog_id; | |
$table = $wpdb->get_blog_prefix($blog->blog_id).'postmeta'; | |
$req = str_replace('%s',$table,$req_tpl); | |
$changes = $wpdb->query($req); | |
echo "$blog_id : ".($changes ? "$changes modifications" : "ok")."\n"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment