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.

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

1 Answer 1

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
            $slug=$original_slug;
        }
        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

 
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.