diff --git src/wp-includes/class-wp.php src/wp-includes/class-wp.php
index efe77ad..8a2f177 100644
--- src/wp-includes/class-wp.php
+++ src/wp-includes/class-wp.php
@@ -308,6 +308,9 @@ class WP {
 			}
 		}
 
+		// Resolve conflicts between posts with numeric slugs and date archive queries.
+		$this->query_vars = wp_resolve_numeric_slug_conflicts( $this->query_vars );
+
 		foreach ( (array) $this->private_query_vars as $var) {
 			if ( isset($this->extra_query_vars[$var]) )
 				$this->query_vars[$var] = $this->extra_query_vars[$var];
diff --git src/wp-includes/post.php src/wp-includes/post.php
index 564d4ee..b0b1391 100644
--- src/wp-includes/post.php
+++ src/wp-includes/post.php
@@ -3770,6 +3770,27 @@ function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p
 		$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1";
 		$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID ) );
 
+		// Prevent post slugs that could result in URLs that conflict with date archives.
+		$conflicts_with_date_archive = false;
+		if ( 'post' === $post_type && 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;
+			}
+		}
+
 		/**
 		 * Filter whether the post slug would be bad as a flat slug.
 		 *
@@ -3779,7 +3800,7 @@ function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p
 		 * @param string $slug      The post slug.
 		 * @param string $post_type Post type.
 		 */
-		if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) {
+		if ( $post_name_check || in_array( $slug, $feeds ) || $conflicts_with_date_archive || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) {
 			$suffix = 2;
 			do {
 				$alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
diff --git src/wp-includes/rewrite.php src/wp-includes/rewrite.php
index 51e3a6b..9a1fad8 100644
--- src/wp-includes/rewrite.php
+++ src/wp-includes/rewrite.php
@@ -277,6 +277,112 @@ function _wp_filter_taxonomy_base( $base ) {
 	return $base;
 }
 
+
+/**
+ * Resolve numeric slugs that collide with date permalinks.
+ *
+ * Permalinks of posts with numeric slugs can sometimes look to `WP_Query::parse_query()` like a date archive,
+ * as when your permalink structure is `/%year%/%postname%/` and a post with post_name '05' has the URL
+ * `/2015/05/`. This function detects these conflicts and resolves conflicts in favor of the post permalink.
+ *
+ * @since 4.3.0
+ *
+ * @param array $query_vars Query variables for setting up the loop, as determined in `WP::parse_request()`.
+ * @return array Returns the original array of query vars, with date/post conflicts resolved.
+ */
+function wp_resolve_numeric_slug_conflicts( $query_vars = array() ) {
+	if ( ! isset( $query_vars['year'] ) && ! isset( $query_vars['monthnum'] ) && ! isset( $query_vars['day'] ) ) {
+		return $query_vars;
+	}
+
+	// Identify the 'postname' position in the permastruct array.
+	$permastructs   = array_values( array_filter( explode( '/', get_option( 'permalink_structure' ) ) ) );
+	$postname_index = array_search( '%postname%', $permastructs );
+
+	if ( false === $postname_index ) {
+		return $query_vars;
+	}
+
+	/*
+	 * A numeric slug could be confused with a year, month, or day, depending on position. To account for
+	 * the possibility of post pagination (eg 2015/2 for the second page of a post called '2015'), our
+	 * `is_*` checks are generous: check for year-slug clashes when `is_year` *or* `is_month`, and check
+	 * for month-slug clashes when `is_month` *or* `is_day`.
+	 */
+	$compare = '';
+	if ( 0 === $postname_index && ( isset( $query_vars['year'] ) || isset( $query_vars['monthnum'] ) ) ) {
+		$compare = 'year';
+	} else if ( '%year%' === $permastructs[ $postname_index - 1 ] && ( isset( $query_vars['monthnum'] ) || isset( $query_vars['day'] ) ) ) {
+		$compare = 'monthnum';
+	} else if ( '%monthnum%' === $permastructs[ $postname_index - 1 ] && isset( $query_vars['day'] ) ) {
+		$compare = 'day';
+	}
+
+	if ( ! $compare ) {
+		return $query_vars;
+	}
+
+	// This is the potentially clashing slug.
+	$value = $query_vars[ $compare ];
+
+	$post = get_page_by_path( $value, OBJECT, 'post' );
+	if ( ! ( $post instanceof WP_Post ) ) {
+		return $query_vars;
+	}
+
+	// If the date of the post doesn't match the date specified in the URL, resolve to the date archive.
+	if ( preg_match( '/^([0-9]{4})\-([0-9]{2})/', $post->post_date, $matches ) && isset( $query_vars['year'] ) && ( 'monthnum' === $compare || 'day' === $compare ) ) {
+		// $matches[1] is the year the post was published.
+		if ( intval( $query_vars['year'] ) !== intval( $matches[1] ) ) {
+			return $query_vars;
+		}
+
+		// $matches[2] is the month the post was published.
+		if ( 'day' === $compare && isset( $query_vars['monthnum'] ) && intval( $query_vars['monthnum'] ) !== intval( $matches[2] ) ) {
+			return $query_vars;
+		}
+	}
+
+	/*
+	 * If the located post contains nextpage pagination, then the URL chunk following postname may be
+	 * intended as the page number. Verify that it's a valid page before resolving to it.
+	 */
+	$maybe_page = '';
+	if ( 'year' === $compare && isset( $query_vars['monthnum'] ) ) {
+		$maybe_page = $query_vars['monthnum'];
+	} else if ( 'monthnum' === $compare && isset( $query_vars['day'] ) ) {
+		$maybe_page = $query_vars['day'];
+	}
+
+	$post_page_count = substr_count( $post->post_content, '<!--nextpage-->' ) + 1;
+
+	// If the post doesn't have multiple pages, but a 'page' candidate is found, resolve to the date archive.
+	if ( 1 === $post_page_count && $maybe_page ) {
+		return $query_vars;
+	}
+
+	// If the post has multiple pages and the 'page' number isn't valid, resolve to the date archive.
+	if ( $post_page_count > 1 && $maybe_page > $post_page_count ) {
+		return $query_vars;
+	}
+
+	// If we've gotten to this point, we have a slug/date clash. First, adjust for nextpage.
+	if ( '' !== $maybe_page ) {
+		$query_vars['page'] = intval( $maybe_page );
+	}
+
+	// Next, unset autodetected date-related query vars.
+	unset( $query_vars['year'] );
+	unset( $query_vars['monthnum'] );
+	unset( $query_vars['day'] );
+
+	// Then, set the identified post.
+	$query_vars['name'] = $post->post_name;
+
+	// Finally, return the modified query vars.
+	return $query_vars;
+}
+
 /**
  * Examine a url and try to determine the post ID it represents.
  *
@@ -392,6 +498,9 @@ function url_to_postid($url) {
 				}
 			}
 
+			// Resolve conflicts between posts with numeric slugs and date archive queries.
+			$query = wp_resolve_numeric_slug_conflicts( $query );
+
 			// Do the query
 			$query = new WP_Query( $query );
 			if ( ! empty( $query->posts ) && $query->is_singular )
diff --git tests/phpunit/tests/admin/includesPost.php tests/phpunit/tests/admin/includesPost.php
index 5d2623a..e25a917 100644
--- tests/phpunit/tests/admin/includesPost.php
+++ tests/phpunit/tests/admin/includesPost.php
@@ -313,4 +313,168 @@ class Tests_Admin_includesPost extends WP_UnitTestCase {
 		$wp_rewrite->set_permalink_structure( $old_permalink_structure );
 		flush_rewrite_rules();
 	}
+
+	/**
+	 * @ticket 5305
+	 */
+	public function test_get_sample_permalink_should_avoid_slugs_that_would_create_clashes_with_year_archives() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$p = $this->factory->post->create( array(
+			'post_name' => '2015',
+		) );
+
+		$found = get_sample_permalink( $p );
+		$this->assertEquals( '2015-2', $found[1] );
+
+		$wp_rewrite->set_permalink_structure( '' );
+		flush_rewrite_rules();
+	}
+
+	/**
+	 * @ticket 5305
+	 */
+	public function test_get_sample_permalink_should_allow_yearlike_slugs_if_permastruct_does_not_cause_an_archive_conflict() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$p = $this->factory->post->create( array(
+			'post_name' => '2015',
+		) );
+
+		$found = get_sample_permalink( $p );
+		$this->assertEquals( '2015', $found[1] );
+
+		$wp_rewrite->set_permalink_structure( '' );
+		flush_rewrite_rules();
+	}
+
+	/**
+	 * @ticket 5305
+	 */
+	public function test_get_sample_permalink_should_avoid_slugs_that_would_create_clashes_with_month_archives() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$p = $this->factory->post->create( array(
+			'post_name' => '11',
+		) );
+
+		$found = get_sample_permalink( $p );
+		$this->assertEquals( '11-2', $found[1] );
+
+		$wp_rewrite->set_permalink_structure( '' );
+		flush_rewrite_rules();
+	}
+
+	/**
+	 * @ticket 5305
+	 */
+	public function test_get_sample_permalink_should_ignore_potential_month_conflicts_for_invalid_monthnum() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$p = $this->factory->post->create( array(
+			'post_name' => '13',
+		) );
+
+		$found = get_sample_permalink( $p );
+		$this->assertEquals( '13', $found[1] );
+
+		$wp_rewrite->set_permalink_structure( '' );
+		flush_rewrite_rules();
+	}
+
+	/**
+	 * @ticket 5305
+	 */
+	public function test_get_sample_permalink_should_avoid_slugs_that_would_create_clashes_with_day_archives() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$p = $this->factory->post->create( array(
+			'post_name' => '30',
+		) );
+
+		$found = get_sample_permalink( $p );
+		$this->assertEquals( '30-2', $found[1] );
+
+		$wp_rewrite->set_permalink_structure( '' );
+		flush_rewrite_rules();
+	}
+
+	/**
+	 * @ticket 5305
+	 */
+	public function test_get_sample_permalink_should_iterate_slug_suffix_when_a_date_conflict_is_found() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$this->factory->post->create( array(
+			'post_name' => '30-2',
+		) );
+
+		$p = $this->factory->post->create( array(
+			'post_name' => '30',
+		) );
+
+		$found = get_sample_permalink( $p );
+		$this->assertEquals( '30-3', $found[1] );
+
+		$wp_rewrite->set_permalink_structure( '' );
+		flush_rewrite_rules();
+	}
+
+	/**
+	 * @ticket 5305
+	 */
+	public function test_get_sample_permalink_should_ignore_potential_day_conflicts_for_invalid_day() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$p = $this->factory->post->create( array(
+			'post_name' => '32',
+		) );
+
+		$found = get_sample_permalink( $p );
+		$this->assertEquals( '32', $found[1] );
+
+		$wp_rewrite->set_permalink_structure( '' );
+		flush_rewrite_rules();
+	}
+
+	/**
+	 * @ticket 5305
+	 */
+	public function test_get_sample_permalink_should_allow_daylike_slugs_if_permastruct_does_not_cause_an_archive_conflict() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%month%/%day%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$p = $this->factory->post->create( array(
+			'post_name' => '30',
+		) );
+
+		$found = get_sample_permalink( $p );
+		$this->assertEquals( '30', $found[1] );
+
+		$wp_rewrite->set_permalink_structure( '' );
+		flush_rewrite_rules();
+	}
 }
diff --git tests/phpunit/tests/post/wpUniquePostSlug.php tests/phpunit/tests/post/wpUniquePostSlug.php
index 019e6bd..3256172 100644
--- tests/phpunit/tests/post/wpUniquePostSlug.php
+++ tests/phpunit/tests/post/wpUniquePostSlug.php
@@ -164,4 +164,172 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
 
 		$this->assertSame( 'foo', $actual );
 	}
+
+	/**
+	 * @ticket 5305
+	 */
+	public function test_slugs_resulting_in_permalinks_that_resemble_year_archives_should_be_suffixed() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$p = $this->factory->post->create( array(
+			'post_type' => 'post',
+			'post_name' => 'foo',
+		) );
+
+		$found = wp_unique_post_slug( '2015', $p, 'publish', 'post', 0 );
+		$this->assertEquals( '2015-2', $found );
+
+		$wp_rewrite->set_permalink_structure( '' );
+		flush_rewrite_rules();
+	}
+
+	/**
+	 * @ticket 5305
+	 */
+	public function test_yearlike_slugs_should_not_be_suffixed_if_permalink_structure_does_not_result_in_a_clash_with_year_archives() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$p = $this->factory->post->create( array(
+			'post_type' => 'post',
+			'post_name' => 'foo',
+		) );
+
+		$found = wp_unique_post_slug( '2015', $p, 'publish', 'post', 0 );
+		$this->assertEquals( '2015', $found );
+
+		$wp_rewrite->set_permalink_structure( '' );
+		flush_rewrite_rules();
+	}
+
+	/**
+	 * @ticket 5305
+	 */
+	public function test_slugs_resulting_in_permalinks_that_resemble_month_archives_should_be_suffixed() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$p = $this->factory->post->create( array(
+			'post_type' => 'post',
+			'post_name' => 'foo',
+		) );
+
+		$found = wp_unique_post_slug( '11', $p, 'publish', 'post', 0 );
+		$this->assertEquals( '11-2', $found );
+
+		$wp_rewrite->set_permalink_structure( '' );
+		flush_rewrite_rules();
+	}
+
+	/**
+	 * @ticket 5305
+	 */
+	public function test_monthlike_slugs_should_not_be_suffixed_if_permalink_structure_does_not_result_in_a_clash_with_month_archives() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/foo/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$p = $this->factory->post->create( array(
+			'post_type' => 'post',
+			'post_name' => 'foo',
+		) );
+
+		$found = wp_unique_post_slug( '11', $p, 'publish', 'post', 0 );
+		$this->assertEquals( '11', $found );
+
+		$wp_rewrite->set_permalink_structure( '' );
+		flush_rewrite_rules();
+	}
+
+	/**
+	 * @ticket 5305
+	 */
+	public function test_monthlike_slugs_should_not_be_suffixed_for_invalid_month_numbers() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$p = $this->factory->post->create( array(
+			'post_type' => 'post',
+			'post_name' => 'foo',
+		) );
+
+		$found = wp_unique_post_slug( '13', $p, 'publish', 'post', 0 );
+		$this->assertEquals( '13', $found );
+
+		$wp_rewrite->set_permalink_structure( '' );
+		flush_rewrite_rules();
+	}
+
+	/**
+	 * @ticket 5305
+	 */
+	public function test_slugs_resulting_in_permalinks_that_resemble_day_archives_should_be_suffixed() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$p = $this->factory->post->create( array(
+			'post_type' => 'post',
+			'post_name' => 'foo',
+		) );
+
+		$found = wp_unique_post_slug( '30', $p, 'publish', 'post', 0 );
+		$this->assertEquals( '30-2', $found );
+
+		$wp_rewrite->set_permalink_structure( '' );
+		flush_rewrite_rules();
+	}
+
+	/**
+	 * @ticket 5305
+	 */
+	public function test_daylike_slugs_should_not_be_suffixed_if_permalink_structure_does_not_result_in_a_clash_with_day_archives() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$p = $this->factory->post->create( array(
+			'post_type' => 'post',
+			'post_name' => 'foo',
+		) );
+
+		$found = wp_unique_post_slug( '30', $p, 'publish', 'post', 0 );
+		$this->assertEquals( '30', $found );
+
+		$wp_rewrite->set_permalink_structure( '' );
+		flush_rewrite_rules();
+	}
+
+	/**
+	 * @ticket 5305
+	 */
+	public function test_daylike_slugs_should_not_be_suffixed_for_invalid_day_numbers() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$p = $this->factory->post->create( array(
+			'post_type' => 'post',
+			'post_name' => 'foo',
+		) );
+
+		$found = wp_unique_post_slug( '32', $p, 'publish', 'post', 0 );
+		$this->assertEquals( '32', $found );
+
+		$wp_rewrite->set_permalink_structure( '' );
+		flush_rewrite_rules();
+	}
 }
diff --git tests/phpunit/tests/rewrite/numericSlugs.php tests/phpunit/tests/rewrite/numericSlugs.php
new file mode 100644
index 0000000..769c65c
--- /dev/null
+++ tests/phpunit/tests/rewrite/numericSlugs.php
@@ -0,0 +1,538 @@
+<?php
+
+/**
+ * @group rewrite
+ * @ticket 5305
+ */
+class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase {
+	private $old_current_user;
+
+	public function setUp() {
+		parent::setUp();
+		$this->author_id = $this->factory->user->create( array( 'role' => 'editor' ) );
+
+		// Override the post/archive slug collision prevention in `wp_unique_post_slug()`.
+		add_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ), 10, 6 );
+	}
+
+	public function tearDown() {
+		remove_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ), 10, 6 );
+	}
+
+	public function test_go_to_year_segment_collision_without_title() {
+		global $wp_rewrite, $wpdb;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$id = $this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => rand_str(),
+			'post_title'   => '',
+			'post_name'    => '2015',
+			'post_date'    => '2015-02-01 01:00:00'
+		) );
+
+		// Force an ID that resembles a year format
+		$wpdb->update(
+			$wpdb->posts,
+			array(
+				'ID'   => '2015',
+				'guid' => 'http://example.org/?p=2015'
+			),
+			array( 'ID' => $id )
+		);
+
+		$this->go_to( get_permalink( '2015' ) );
+
+		$this->assertQueryTrue( 'is_single', 'is_singular' );
+
+		$wp_rewrite->set_permalink_structure('');
+	}
+
+	public function test_url_to_postid_year_segment_collision_without_title() {
+		global $wp_rewrite, $wpdb;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$id = $this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => rand_str(),
+			'post_title'   => '',
+			'post_name'    => '2015',
+			'post_date'    => '2015-02-01 01:00:00'
+		) );
+
+		// Force an ID that resembles a year format
+		$wpdb->update(
+			$wpdb->posts,
+			array(
+				'ID'   => '2015',
+				'guid' => 'http://example.org/?p=2015'
+			),
+			array( 'ID' => $id )
+		);
+
+		$this->assertEquals( '2015', url_to_postid( get_permalink( '2015' ) ) );
+
+		$wp_rewrite->set_permalink_structure('');
+	}
+
+	public function test_go_to_year_segment_collision_with_title() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$id = $this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => rand_str(),
+			'post_title'   => '2015',
+			'post_date'    => '2015-02-01 01:00:00',
+		) );
+
+		$this->go_to( get_permalink( $id ) );
+
+		$this->assertQueryTrue( 'is_single', 'is_singular' );
+
+		$wp_rewrite->set_permalink_structure('');
+	}
+
+	public function test_url_to_postid_year_segment_collision_with_title() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$id = $this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => rand_str(),
+			'post_title'   => '2015',
+			'post_date'    => '2015-02-01 01:00:00',
+		) );
+
+		$this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
+
+		$wp_rewrite->set_permalink_structure('');
+	}
+
+	public function test_go_to_month_segment_collision_without_title() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$id = $this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => rand_str(),
+			'post_title'   => '',
+			'post_name'    => '02',
+			'post_date'    => '2015-02-01 01:00:00',
+		) );
+
+		$this->go_to( get_permalink( $id ) );
+
+		$this->assertQueryTrue( 'is_single', 'is_singular' );
+
+		$wp_rewrite->set_permalink_structure('');
+	}
+
+	public function test_url_to_postid_month_segment_collision_without_title() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$id = $this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => rand_str(),
+			'post_title'   => '',
+			'post_name'    => '02',
+			'post_date'    => '2015-02-01 01:00:00',
+		) );
+
+		$this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
+
+		$wp_rewrite->set_permalink_structure('');
+	}
+
+	public function test_go_to_month_segment_collision_without_title_no_leading_zero() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$id = $this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => rand_str(),
+			'post_title'   => '',
+			'post_name'    => '2',
+			'post_date'    => '2015-02-01 01:00:00',
+		) );
+
+		$this->go_to( get_permalink( $id ) );
+
+		$this->assertQueryTrue( 'is_single', 'is_singular' );
+
+		$wp_rewrite->set_permalink_structure('');
+	}
+
+	public function test_url_to_postid_month_segment_collision_without_title_no_leading_zero() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$id = $this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => rand_str(),
+			'post_title'   => '',
+			'post_name'    => '2',
+			'post_date'    => '2015-02-01 01:00:00',
+		) );
+
+		$this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
+
+		$wp_rewrite->set_permalink_structure('');
+	}
+
+	public function test_go_to_month_segment_collision_with_title() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$id = $this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => rand_str(),
+			'post_title'   => '02',
+			'post_date'    => '2015-02-01 01:00:00',
+		) );
+
+		$this->go_to( get_permalink( $id ) );
+
+		$this->assertQueryTrue( 'is_single', 'is_singular' );
+
+		$wp_rewrite->set_permalink_structure('');
+	}
+
+	public function test_url_to_postid_month_segment_collision_with_title() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$id = $this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => rand_str(),
+			'post_title'   => '02',
+			'post_date'    => '2015-02-01 01:00:00',
+		) );
+
+		$this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
+
+		$wp_rewrite->set_permalink_structure('');
+	}
+
+	public function test_go_to_month_segment_collision_with_title_no_leading_zero() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$id = $this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => rand_str(),
+			'post_title'   => '2',
+			'post_date'    => '2015-02-01 01:00:00',
+		) );
+
+		$this->go_to( get_permalink( $id ) );
+
+		$this->assertQueryTrue( 'is_single', 'is_singular' );
+
+		$wp_rewrite->set_permalink_structure('');
+	}
+
+	public function test_url_to_postid_month_segment_collision_with_title_no_leading_zero() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$id = $this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => rand_str(),
+			'post_title'   => '2',
+			'post_date'    => '2015-02-01 01:00:00',
+		) );
+
+		$this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
+
+		$wp_rewrite->set_permalink_structure('');
+	}
+
+	public function test_go_to_day_segment_collision_without_title() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$id = $this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => rand_str(),
+			'post_title'   => '',
+			'post_name'    => '01',
+			'post_date'    => '2015-02-01 01:00:00',
+		) );
+
+		$this->go_to( get_permalink( $id ) );
+
+		$this->assertQueryTrue( 'is_single', 'is_singular' );
+
+		$wp_rewrite->set_permalink_structure('');
+	}
+
+	public function test_url_to_postid_day_segment_collision_without_title() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$id = $this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => rand_str(),
+			'post_title'   => '',
+			'post_name'    => '01',
+			'post_date'    => '2015-02-01 01:00:00',
+		) );
+
+		$this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
+
+		$wp_rewrite->set_permalink_structure('');
+	}
+
+	public function test_go_to_day_segment_collision_with_title() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$id = $this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => rand_str(),
+			'post_title'   => '01',
+			'post_date'    => '2015-02-01 01:00:00',
+		) );
+
+		$this->go_to( get_permalink( $id ) );
+
+		$this->assertQueryTrue( 'is_single', 'is_singular' );
+
+		$wp_rewrite->set_permalink_structure('');
+	}
+
+	public function test_url_to_postid_day_segment_collision_with_title() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$id = $this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => rand_str(),
+			'post_title'   => '01',
+			'post_date'    => '2015-02-01 01:00:00',
+		) );
+
+		$this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
+
+		$wp_rewrite->set_permalink_structure('');
+	}
+
+	public function test_numeric_slug_permalink_conflicts_should_only_be_resolved_for_the_main_query() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$id = $this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => rand_str(),
+			'post_title'   => '01',
+			'post_date'    => '2015-02-01 01:00:00',
+		) );
+
+		$q = new WP_Query( array(
+			'year'     => '2015',
+			'monthnum' => '02',
+			'day'      => '01',
+		) );
+
+		$this->assertTrue( $q->is_day );
+		$this->assertFalse( $q->is_single );
+
+		$wp_rewrite->set_permalink_structure('');
+	}
+
+	public function test_month_slug_collision_should_resolve_to_date_archive_when_year_does_not_match_post_year() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		// Make sure a post is published in 2013/02, to avoid 404s.
+		$this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => 'foo',
+			'post_title'   => 'bar',
+			'post_date'    => '2013-02-01 01:00:00',
+		) );
+
+		$id = $this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => 'foo',
+			'post_title'   => '02',
+			'post_date'    => '2015-02-01 01:00:00',
+		) );
+
+		$permalink = get_permalink( $id );
+		$permalink = str_replace( '/2015/', '/2013/', $permalink );
+
+		$this->go_to( $permalink );
+
+		$this->assertTrue( is_month() );
+	}
+
+	public function test_day_slug_collision_should_resolve_to_date_archive_when_monthnum_does_not_match_post_month() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		// Make sure a post is published on 2015/01/01, to avoid 404s.
+		$this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => 'foo',
+			'post_title'   => 'bar',
+			'post_date'    => '2015-01-02 01:00:00',
+		) );
+
+		$id = $this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => 'foo',
+			'post_title'   => '02',
+			'post_date'    => '2015-02-02 01:00:00',
+		) );
+
+		$permalink = get_permalink( $id );
+		$permalink = str_replace( '/2015/02/', '/2015/01/', $permalink );
+
+		$this->go_to( $permalink );
+
+		$this->assertTrue( is_day() );
+	}
+
+	public function test_date_slug_collision_should_distinguish_valid_pagination_from_date() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$id = $this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => 'Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3',
+			'post_title'   => '02',
+			'post_date'    => '2015-02-01 01:00:00',
+		) );
+
+		$this->go_to( get_permalink( $id ) . '1' );
+
+		$this->assertFalse( is_day() );
+	}
+
+	public function test_date_slug_collision_should_distinguish_too_high_pagination_from_date() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$id = $this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => 'Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3',
+			'post_title'   => '02',
+			'post_date'    => '2015-02-05 01:00:00',
+		) );
+
+		$this->go_to( get_permalink( $id ) . '5' );
+
+		$this->assertTrue( is_day() );
+	}
+
+	public function test_date_slug_collision_should_not_require_pagination_query_var() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$id = $this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => 'Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3',
+			'post_title'   => '02',
+			'post_date'    => '2015-02-05 01:00:00',
+		) );
+
+		$this->go_to( get_permalink( $id ) );
+
+		$this->assertQueryTrue( 'is_single', 'is_singular' );
+		$this->assertFalse( is_date() );
+	}
+
+	public function test_date_slug_collision_should_be_ignored_when_pagination_var_is_present_but_post_does_not_have_multiple_pages() {
+		global $wp_rewrite;
+		$wp_rewrite->init();
+		$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
+		$wp_rewrite->flush_rules();
+
+		$id = $this->factory->post->create( array(
+			'post_author'  => $this->author_id,
+			'post_status'  => 'publish',
+			'post_content' => 'This post does not have pagination.',
+			'post_title'   => '02',
+			'post_date'    => '2015-02-05 01:00:00',
+		) );
+
+		$this->go_to( get_permalink( $id ) . '5' );
+
+		$this->assertTrue( is_day() );
+	}
+
+	public function filter_unique_post_slug( $slug, $post_id, $post_status, $post_type, $post_parent, $original_slug ) {
+		return $original_slug;
+	}
+}
