Server and Network Monitoring with iPhone
February 25, 2010 – 6:53 pm | No Comment

What is a Unix sysadmin doing with an iPhone, you ask? It was a birthday present, if that’s all right with you. I know, I should have gotten something odd with a beta version of …

Read the full story »
Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands and Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Commands and Shells, MySQL, WordPress

Remove Duplicate Posts in WordPress

Submitted by Igor on December 5, 2009 – 10:28 pmNo Comment
Remove Duplicate Posts in WordPress

Below is the SQL script that will attempt to identify and remove duplicate posts in your WordPress database. This script can be useful for autoblogging. If you use plugins like WP-o-Matic to pull full-text RSS feeds into your database, you will inevitably end up with a bunch of duplicate articles. This is not good as many search engines – including Google – frown upon duplicate content and may decide not to index much of your site.

Edit the script and add your database information. You may need to change “wp_posts” to “_posts”. Before using the script, backup your database. There is no “undo” button in the script. If you are happy with the result, set up a cron job to run the script twice every day. Keep in mind that the script is looking for duplicate post titles. It does not look at the actual post content. Do not use this script if you purposefully have different posts with the same title.

#!/bin/ksh
 
MYSQL=/usr/bin/mysql
DBUSER=your_db_username
DBPASS=your_db_password
DBNAME=db_name
 
$MYSQL -u$DBUSER -p$DBPASS $DBNAME << EOF
 
        DELETE bad_rows.*
        from wp_posts as bad_rows
        inner join (
                select post_title, MIN(id) as min_id
                from wp_posts
                group by post_title
                having count(*) > 1
        ) as good_rows on good_rows.post_title = bad_rows.post_title
        and good_rows.min_id <> bad_rows.id ;
EOF

Popularity: 3% [?]

Related posts

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.