get_results("SELECT post_name, ID FROM $wpdb->posts WHERE post_name LIKE '$_title%'"); if (!$posts) return $title; $suffix = ''; do { $ok = true; foreach ($posts as $post) { if ($post_ID == $post->ID) { continue; } // skip self if ($title.$suffix == $post->post_name) { // is permalink unique? $suffix++; // change suffix $ok = false; // and tray again break; } } } while ($ok == false); return $title.$suffix; } add_action('sanitize_title', 'sanitize_unique', 20); // 20 - low priority! ?>