diff --git src/wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php src/wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php
index e03af6e357..56acfb7697 100644
|
|
class WP_Sitemaps_Posts extends WP_Sitemaps_Provider { |
174 | 174 | |
175 | 175 | $query = new WP_Query( $args ); |
176 | 176 | |
177 | | return isset( $query->max_num_pages ) ? $query->max_num_pages : 1; |
| 177 | $min_num_pages = ( 'page' === $post_type && 'posts' === get_option( 'show_on_front' ) ) ? 1 : 0; |
| 178 | return isset( $query->max_num_pages ) ? max( $min_num_pages, $query->max_num_pages ) : 1; |
178 | 179 | } |
179 | 180 | |
180 | 181 | /** |
diff --git tests/phpunit/tests/sitemaps/sitemaps-posts.php tests/phpunit/tests/sitemaps/sitemaps-posts.php
index 8d173942f4..d102518587 100644
|
|
|
4 | 4 | * @group sitemaps |
5 | 5 | */ |
6 | 6 | class Test_WP_Sitemaps_Posts extends WP_UnitTestCase { |
| 7 | /** |
| 8 | * Tests getting sitemap entries for post type page with 'posts' homepage. |
| 9 | * |
| 10 | * Ensures that an entry is added even if there are no pages. |
| 11 | * |
| 12 | * @ticket 50571 |
| 13 | */ |
| 14 | public function test_get_sitemap_entries_homepage() { |
| 15 | update_option( 'show_on_front', 'posts' ); |
| 16 | |
| 17 | $posts_provider = new WP_Sitemaps_Posts(); |
| 18 | |
| 19 | $post_list = $posts_provider->get_sitemap_entries(); |
| 20 | |
| 21 | $expected = array( |
| 22 | array( |
| 23 | 'loc' => home_url( '/?sitemap=posts&sitemap-subtype=page&paged=1' ), |
| 24 | ), |
| 25 | ); |
| 26 | |
| 27 | $this->assertEquals( $expected, $post_list ); |
| 28 | } |
| 29 | |
7 | 30 | /** |
8 | 31 | * Test ability to filter object subtypes. |
9 | 32 | */ |