0

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');
1

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');
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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