Problem with url incrementation (post-type-1-1-1)

Forums Forums Remove CPT base Problem with url incrementation (post-type-1-1-1)

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #204

    Hi there,
    I need help with something I don’t understand.

    I’ve got a Page with the name “Tarifs” and the slug is

    I’ve got a few CPT with these structure :

    The problem is my cpt slug are not :
    but (and same thing for city2, city3…)

    And one more thing, very problematic, is everytime I update my CPT the slug add -1 until 5 times, like this

    Temporarily I commented : add_filter( ‘wp_unique_post_slug’, array( $this, ‘fix_slug’ ), 100, 6 );
    and it works but I would prefer a real Dev solution 😉

    Thanks for your help



    every post should have unique post_name, this is how WordPress works.
    Of course, there are many ways how to get around it, but it depends on specific setup.
    Maximum what I can do is to create checkbox for disabling unique slugs, but it can cause many problems for many users.

    The thing is, that in general, when you need so many same post_names, you’re doing something wrong. For example in your case I recommend to use custom endpoint instead of creating subpost for every post.

    Put this in you functions.php

    add_filter( 'query_vars', 'add_query_vars' );
    function add_query_vars( $vars ){
    	$vars[] = 'tarifs';
    	return $vars;
    add_rewrite_endpoint( 'tarifs', EP_PERMALINK );

    then in single-city.php use $wp_query->query['tarifs']


    Sorry for the delay.
    Thank you for your support.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.