Make WordPress Core

Changeset 48476

Timestamp:
07/14/2020 12:24:02 PM (4 years ago)
Author:
swissspidy
Message:

Sitemaps: Ensure entry for ‘page’ post type sitemap in index.

If there are no pages and no static homepage, there will still be one sitemap including the homepage URL.

This change ensures that this sitemap is correctly listed in the sitemap index.

Props Chouby, pacifika, elrae.
Fixes #50571.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php

    r48474 r48476  
    175175        $query = new WP_Query( $args );
    176176
    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;
    178179    }
    179180
  • trunk/tests/phpunit/tests/sitemaps/sitemaps-posts.php

    r48072 r48476  
    55 */
    66class Test_WP_Sitemaps_Posts extends WP_UnitTestCase {
     7
     8
     9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
    730    /**
    831     * Test ability to filter object subtypes.
Note: See TracChangeset for help on using the changeset viewer.