<?php
/*
Plugin Name: Delete duplicate posts
Plugin URI:
Description: Deletes duplicate posts based on their title
Author: Mitsuki Fukunaga
Version: 1.0
Author URI:
*/
function WPDeleteDuplicates(){
global $wpdb;
$wpdbprefix = $wpdb->prefix;
$wpdb->query("
DELETE FROM ".$wpdbprefix."posts
WHERE ".$wpdbprefix."posts.ID not in (
select max_id from (
SELECT MAX(t1.ID) AS max_id
FROM ".$wpdbprefix."posts AS t1
WHERE t1.post_type = 'post'
GROUP BY t1.post_title
) as t2
) AND ".$wpdbprefix."posts.post_type = 'post'
");
}
add_action('publish_post', 'WPDeleteDuplicates');
?>
Showing posts with label wordpress. Show all posts
Showing posts with label wordpress. Show all posts
Friday, 22 November 2013
WordPress で重複記事を削除するプラグインを作ったよ。
WordPressで重複記事を削除するための"Delete all duplicate posts"ってプラグインがあるんですが、なんかうまく動かないので、自分で作りなおしました。タイトルが同じ記事がアップされると、古いバージョンの投稿は自動で削除されます。
Labels:
wordpress
Subscribe to:
Posts (Atom)