Wordpress - Why can't I save permalink "360" for a page?

The problem comes with using only numbers as URLs. Here is a forum thread in WP that discuss this issue. I'll cite Otto:

WordPress 2.3 and up does not allow the post or page slugs to be all numeric. This is because that URL scheme will conflict with multi-page posts.

There is no fix. Change them to something else.

Alternatively, a plugin exists to allow this, if you give up on multi-page posting: http://wordpress.org/extend/plugins/allow-numeric-stubs/

More info here: http://trac.wordpress.org/ticket/5305


If we check out the source of the wp_unique_post_slug() function, then we see that this is expected for hierarchical post types, other than nav_menu_item.

If we try for example the slugs 360 or page360, then the -n slug suffix will show up.

We can play with e.g.:

echo wp_unique_post_slug( 
    $slug        = '360', 
    $post_id     = '', 
    $post_status = '', 
    $post_type   = 'page' 
);

or

echo wp_unique_post_slug( 
    $slug        = 'page360', 
    $post_id     = '', 
    $post_status = '', 
    $post_type   = 'page' 
);

to see that.

One of the "bad slug" checks, within wp_unique_post_slug(), is this one:

preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug ) 

It's matched in your case:

preg_match( "@^(page)?\d+$@", '360' ) 

hence the resulting slug suffix.

You can also play with it here:

https://regex101.com/r/jF3kC6/1

Note that it's possible to modify the slug via the wp_unique_post_slug filter, but one should be really careful doing that.

Tags:

Permalinks