Skip Navigation

[Closed] Single character slug for custom post type

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 3 replies, has 1 voice.

Last updated by Christopher Amirian 2 weeks, 4 days ago.

Assisted by: Christopher Amirian.

Author
Posts
#2785359

Hi,

This ticket relates to the previous ticket, which I did not have time to answer: https://toolset.com/forums/topic/complicated-site-structure-with-combined-categories-and-subcategories/

Unfortunately, I am unable to use some of the single letters in the CPT slug (such as the letter “/p/” or “/m/”). Other letters, such as the letter “/l/” or “/u/” could be used without a problem.

It seems to me that the problem is that at the very beginning of the creation of the site I created a CPT with the aforementioned letters, and then removed them. Perhaps the issue is that somewhere in the database this continues to be stored and is not properly removed by Toolset?

Your help is appreciated! Thank you.

#2785482

Christopher Amirian
Supporter

Languages: English (English )

Hi,

To test this I created a new installation of WordPress and Toolset and specifically tested for P and M. ANd the same thing happened. I have got this error:

You cannot use this slug because it is already used or a reserved word. Please choose a different slug.

As the error suggests the "p" keyword is reserved. I tested by adding the custom post type via code with code.

It created the post type, but adding the content did not work and led to 404 page.

So it seems there is a WordPress native restriction regarding at least the "p" character there.

You can check what I have done in this installation:

hidden link

Thanks.

#2786914

Hi Chrisopher,

Can you point me to a solution for how, in the case of Toolset, I can bypass this restriction by using the rewrite->slug parameter?

'rewrite' => array(
'slug' => 'k',
'with_front' => false,
'pages' => false,
'feeds' => false,
);

Thank you!

#2787235

Christopher Amirian
Supporter

Languages: English (English )

Hi,

The issue you're encountering is related to WordPress's reserved terms and core functionality. Certain single-character slugs like /p/ and /m/ are reserved or used internally by WordPress, which makes them unavailable for custom post types or other purposes. Even if the CPT creation succeeds, conflicts can arise in permalinks or query handling, leading to 404 errors.

I don't think there will be a robust way to bypass such restriction as you will encounter issues along the way and we can not guarantee a smooth working solution.

A typical rewrite solution would be like this:

function register_custom_post_type_with_reserved_slug() {
    register_post_type('custom_slug_p', array(
        'labels' => array(
            'name' => 'Custom Slug P',
            'singular_name' => 'Custom Slug P'
        ),
        'public' => true,
        'has_archive' => true,
        'rewrite' => array(
            'slug' => 'p', // Use the reserved slug
            'with_front' => false,
            'pages' => false,
            'feeds' => false,
        ),
        'supports' => array('title', 'editor', 'thumbnail'),
    ));
}
add_action('init', 'register_custom_post_type_with_reserved_slug');

But I am almost sure you will encounter conflicts along the way so I do recommend to avoid using such scenarios.

Thanks.

The topic ‘[Closed] Single character slug for custom post type’ is closed to new replies.