Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.