• As everybody knows you cannot have PAGES and CUSTOM TYPES with the same name, otherwise you can get a 404 (error) page with pagination and other kinds of problems.

    While it makes sense that WP gets troubled from having to manage 2 URLs with the same name, how limiting is the fact that there is no solution to keep a logical permalinks consistency?

    For example:
    You want to have a SECTION of your website called “Agenda“, to hold events under that section, and therefore would like this permalinks structure:

    websitename.com/agenda (index of events)
    websitename.com/agenda/event-name-1 (event 1)
    websitename.com/agenda/event-name-2( event 2)
    … and do on.

    You create a CUSTOM TYPE called “agenda”, so that the events index lives under that slug (websitename.com/agenda/event-name-1).

    But you also need to create a PAGE with a slug of “agenda” with a page template with a loop for the “agenda” CUTOM TYPE, in order to get “websitename.com/agenda” which is the index of events.

    But WordPress tells you, you can’t!

    The community is aware of this limitation and the easy solution for everybody to deal with such a problem is to change either the PAGE name or the CUSTOM TYPE name, like advised everywhere:

    https://wpveda.com/solved-wordpress-custom-post-type-and-404-issue/
    https://www.wordimpressed.com/wordpress/solve-wordpress-custom-post-type-404-error-issues/
    https://modernsparkmedia.com/393/wordpress-pagination-with-custom-post-type/
    https://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpress#comment-188256

    But changing the CUSTOM TYPE NAME to something like “events” is not a solution, is it? Because you end up having “websitename.com/events/event-name-1” when you wanted “websitename.com/agenda/event-name-1”.

    So, I wonder, how come nobody seems to care about such a limitation? What if a CLIENT wants to have that kind of URL structure, with all the events under “Agenda”? How do you go and explain that he cannot, that WordPress is limited when it comes to wanted something like this?

    Really, I can’t believe that in the whole WordPress community nobody is facing this problem and nobody has a solution, or put it out there.

Viewing 4 replies - 16 through 19 (of 19 total)
  • Here’s a strange thing then.

    In my ignorance (having never heard of this issue) I created a page called “events” and a custom post type also called “events” and haven’t ever had any problems with it!

    I’m currently using WP 3.1.3 and use Custom Post Type UI plugin 0.7. Permalink structure is set to /%category%/%postname%/. Only other thing I can think of that might effect this is SEO Ultimate.

    Am I lucky or have they fixed this? It must be said, though, that I don’t use pagination but the URLs work perfectly.

    Peter

    beR-

    (@76blueberries)

    Hi community,

    It semms I’ve just found the solution to keep the same name for pages and custom post_type.
    In the definition of your custom post_type, just use add_rewrite_rule to redefine the traitment of the url :

    add_rewrite_rule("{$post}" . '$', "index.php?pagename={$post}", "top");
    add_rewrite_rule("{$post}" . '/page/([0-9])*/?', "index.php?pagename={$post}" . '&paged=$matches[1]', "top");
    
    global $wp_rewrite;
    $wp_rewrite->flush_rules(); // !!!

    Here {$post} correspond to your post_type “agenda” or “event”. You can simplify syntaxe. Here is my whole function :

    /**
     * Rewrite buzz permalink with '/{post_type}/%year%/%monthnum%/%day%/%buzz%/' structure
     */
    function ml_rewrite_permalink($post){
    	// Rewrite buzz permalink with '/buzz/%year%/%monthnum%/%day%/%buzz%/' structure
    	add_rewrite_tag( "%{$post}%", '([^/]+)' );
    	$extra_post_types = get_post_types( array( '_builtin' => false, 'publicly_queryable' => true ) );
    	if( empty( $extra_post_types ) )
    		return;
    	add_rewrite_tag( '%post_type%', '('.implode('|',$extra_post_types).')' );
    	add_permastruct( $post, "/%post_type%/%year%/%monthnum%/%day%/%{$post}%/", true, 1 );
    	add_rewrite_rule("{$post}" . '$', "index.php?pagename={$post}", "top");
    	add_rewrite_rule("{$post}" . '/page/([0-9])*/?', "index.php?pagename={$post}" . '&paged=$matches[1]', "top");
    	global $wp_rewrite;
    	$wp_rewrite->flush_rules(); // !!!
    }

    If any question, feel free to continue the thread.

    nice day,

    beR-

    Hi beR-,

    If you get a minute, could you have a glance at this? – https://www.ads-software.com/support/topic/universal-permalink-structure-across-post-types-not-pages?replies=3

    Cheers,
    Robert

Viewing 4 replies - 16 through 19 (of 19 total)
  • The topic ‘PAGES and CUSTOM TYPES cannot have the same name, so how to structure permalinks’ is closed to new replies.