5

First, I thought I was going crazy and then after additional troubleshooting, it turns out I'm not!

So, I wanted to create a page called 2017, but every time I create a page that begins with a number WordPress appends a "-2" at the end.

I thought it was something in my theme or some images I had that already had the same name, so I tried all kinds of weird numbers that I definitely wasn't using other places and WordPress still appends a "-2" at the end.

Then I figured, ok, so let's disable my theme (enabled the WordPress default) and plugins to isolate the issue...the issue persisted.

Nothing is in the trash, there are no matching post or page names (not even images)

Finally, I was like, let me try this on another site - different images, different theme, different plugins, different everything...the issue persisted.

So, now I think this is a WordPress thing. Is there a way to fix this?

Basically, to reproduce try and create a page that starts with a number - could be 2005, 1999, or 2017 - the only thing I have noticed is that it has to start with a number.

Am I missing something?

11

Within the wp_unique_post_slug function, checks are made to "Prevent new post slugs that could result in URLs that conflict with date archives." Here's the relevant code from line 3812 from wp-includes/post.php

    // Prevent new post slugs that could result in URLs that conflict with date archives.
    $post = get_post( $post_ID );
    $conflicts_with_date_archive = false;
    if ( 'post' === $post_type && ( ! $post || $post->post_name !== $slug ) && preg_match( '/^[0-9]+$/', $slug ) && $slug_num = intval( $slug ) ) {
        $permastructs   = array_values( array_filter( explode( '/', get_option( 'permalink_structure' ) ) ) );
        $postname_index = array_search( '%postname%', $permastructs );

        /*
         * Potential date clashes are as follows:
         *
         * - Any integer in the first permastruct position could be a year.
         * - An integer between 1 and 12 that follows 'year' conflicts with 'monthnum'.
         * - An integer between 1 and 31 that follows 'monthnum' conflicts with 'day'.
         */
        if ( 0 === $postname_index ||
            ( $postname_index && '%year%' === $permastructs[ $postname_index - 1 ] && 13 > $slug_num ) ||
            ( $postname_index && '%monthnum%' === $permastructs[ $postname_index - 1 ] && 32 > $slug_num )
        ) {
            $conflicts_with_date_archive = true;
        }
    }
  • Well, at least I'm not going crazy! I guess I'll just name it something else. Thank you for the clarification, it's good to understand why it's happening :-) – Josh Rodgers Jan 9 '18 at 15:43
  • Not crazy ;) I wasn't aware of this either until now. – Andrew Jan 9 '18 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.