WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Im using this code to prevent duplicate post from being added but i also need to prevent duplicate pages too. Can Someone please help?

function clearDuplicatePosts(){
    global $wpdb;
    $prefix = $wpdb->prefix;
    $wpdb->query("DELETE bad_rows . * FROM ".$prefix."posts AS bad_rows INNER JOIN (
    SELECT ".$prefix."posts.post_title, MIN( ".$prefix."posts.ID ) AS min_id
    FROM ".$prefix."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 )");
add_action('publish_post', 'clearDuplicatePosts');
share|improve this question
up vote 1 down vote accepted

you can use the same function simply hook it to the publish_page hook or any custom post type for that matter publish_{post type name}

so just add :

add_action('publish_page', 'clearDuplicatePosts');
share|improve this answer
That Worked Thanks.. – Jeremy Love Aug 8 '11 at 8:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.