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?