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

I have a situation where it is needed that if I create two CPT pages wich both have the same name and the same slug.

For example, if I add two CPT pages, wich both called "Post Name":
The first slug will be "post-name",
The second slug will be "post-name-2".

Because I added a custom part to the permalink structure wich will make the URL unique:

function extra_post_link( $permalink, $post, $leavename ) {
    global $wp_rewrite;

    if ( stripos( $permalink, '%selected_meta%' ) == false )
        return $permalink;

    if ( is_object( $post ) && ($post->post_type == 'ervaring' || $post->post_type == 'lening') ) {
        $_selected_post_slug = '';
        $_selected_post_id = get_post_meta( $post->ID, 'rating-post', true );

        if ( $_selected_post_id )
            $_selected_post_slug = get_page_uri( $_selected_post_id );

        return str_replace( '%selected_meta%', $_selected_post_slug, $permalink );

    return $permalink;

add_filter( 'post_type_link', 'extra_post_link', 10, 3 );

How do I prevent WordPress from doing this?

share|improve this question
up vote 2 down vote accepted

you might consider the 'wp_unique_post_slug' filter:

   add_filter( 'wp_unique_post_slug','my_disable_unique_slug',11,6);
    function disable_unique_slug( $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ){
        global $post;       
        if($post->post_type=='cpt'){ // EDIT post type
        return $slug;

This is untested, but you get the idea ;-)

ps: you might have to change other things to make this work, since the unique-ness is so important.

share|improve this answer
Oh thank you very much! I sure have to change some other things in order to receive the correct post when the item is viewed. But since that wasn't exactly the question, I consider this one answered. :-) – Mike Madern Feb 6 '13 at 13:09
ok thanks, good luck with your project. – birgire Feb 6 '13 at 15:02

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.