Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#50571 closed defect (bug) (fixed)

Homepage missing in the sitemap

Reported by: chouby's profile Chouby Owned by: swissspidy's profile swissspidy
Milestone: 5.5 Priority: normal
Severity: normal Version: 5.5
Component: Sitemaps Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

On a fresh install,

  1. Unpublish the sample page to make sure that no page is published.
  2. Go to the sitemaps index.

There is no entry for pages as we could expect. But as the hompepage is listed in the list of pages, that means that the homepage is not indexed.

The issue is because the method WP_Sitemaps_Posts::get_max_num_pages() returns 0 when there are no pages.

Attachments (4)

0001-Fix-50571-List-homepage-when-site-contains-no-pages.patch (939 bytes) - added by pacifika 4 years ago.
Minimum 1 sitemap for pages.
0001-Fix-50571-List-homepage-when-site-contains-no-pages-formatted.patch (944 bytes) - added by pacifika 4 years ago.
Formatted version of the previous attachment.
50571.diff (627 bytes) - added by elrae 4 years ago.
sets minimum pages to 1 on pages
50571.2.diff (1.6 KB) - added by swissspidy 4 years ago.

Download all attachments as: .zip

Change History (13)

#1 @swissspidy
4 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 5.5

This ticket was mentioned in Slack in #core-sitemaps by swissspidy. View the logs.


4 years ago

This ticket was mentioned in Slack in #core-sitemaps by swissspidy. View the logs.


4 years ago

@pacifika
4 years ago

Formatted version of the previous attachment.

#4 @swissspidy
4 years ago

My initial thought was more like this:

$min_num_pages =  ( 'page' === $post_type && 1 === $page_num && 'posts' === get_option( 'show_on_front' ) ) ? 1 : 0;

@elrae
4 years ago

sets minimum pages to 1 on pages

#5 @elrae
4 years ago

I've added a patch with your approach @swissspidy but I excluded the 1 === $pagenum as that variable isn't available in this function. There's also no $paged in there to know if we're on the first page. However, the check against 'page' === $post_type and the max($min_num_pages, $query->max_num_pages) should cover us

Version 0, edited 4 years ago by elrae (next)

#6 @elrae
4 years ago

  • Keywords has-patch added; needs-patch removed

#7 @swissspidy
4 years ago

  • Keywords needs-unit-tests added

@swissspidy
4 years ago

#8 @swissspidy
4 years ago

  • Keywords has-unit-tests added; needs-unit-tests removed

#9 @swissspidy
4 years ago

  • Owner set to swissspidy
  • Resolution set to fixed
  • Status changed from new to closed

In 48476:

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.

Note: See TracTickets for help on using tickets.