I've registered a custom post type on my site but loads of different users are able to create posts with the same slug / permalink, here is how I am registering my post type

// Bucket Custom Post Type
function bucket_init() {
// set up bucket labels
$labels = array(
    'name' => 'Buckets',
    'singular_name' => 'Bucket',
    'add_new' => 'Add New Bucket',
    'add_new_item' => 'Add New Bucket',
    'edit_item' => 'Edit Bucket',
    'new_item' => 'New Bucket',
    'all_items' => 'All Buckets',
    'view_item' => 'View Bucket',
    'search_items' => 'Search Buckets',
    'not_found' =>  'No Buckets Found',
    'not_found_in_trash' => 'No Buckets found in Trash', 
    'parent_item_colon' => '',
    'menu_name' => 'Buckets',

// register post type
$args = array(
    'labels' => $labels,
    'public' => true,
    'has_archive' => false,
    'show_ui' => true,
    'capability_type' => 'post',
    'hierarchical' => true,
    'rewrite' => array('slug' => 'bucket'),
    'query_var' => true,
    'menu_icon' => 'dashicons-editor-bold',
    'menu_position' => 20,
    'taxonomies' => array('category', 'post_tag') ,
    'supports' => array(

register_post_type( 'bucket', $args );

 add_action( 'init', 'bucket_init' );

 * Hooks the WP cpt_post_types filter 
 * @param array $post_types An array of post type names that the     templates be used by
 * @return array The array of post type names that the templates be     used by
function my_cpt_post_types( $post_types ) {
$post_types[] = 'bucket';
$post_types[] = 'actor';
return $post_types;
add_filter( 'cpt_post_types', 'my_cpt_post_types' );

So if a user creates a post called hello, and another creates a post with same name it doesn't add a unique number after for example; hello-2. Is there a way I can easily do this..

Or ideally.. Can I set it just be post id instead?

This post type goes 3 levels deep, here is it in action:


So a user can create a bucket, then a folder, then a resource.

I have over 400 users sign up in one day, so whatever I change needs to resolve all existing posts without there being any issues.


Your Answer

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

Browse other questions tagged or ask your own question.