Skip to content

Commit

Permalink
Sitemaps: ensure one item in a news sitemap to ensure validitiy (#40893)
Browse files Browse the repository at this point in the history
  • Loading branch information
kraftbj authored Jan 24, 2025
1 parent 4daa973 commit 3bfae29
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/fix-empty-news
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: bugfix

Sitemaps: ensures a valid news sitemap is present even if no posts are eligible.
13 changes: 8 additions & 5 deletions projects/plugins/jetpack/modules/sitemaps/sitemap-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1087,12 +1087,15 @@ public function news_sitemap_xml() {
);

$posts = $this->librarian->query_most_recent_posts( JP_NEWS_SITEMAP_MAX_ITEMS );
if ( empty( $posts ) ) {
$buffer->append( array( 'url' => array( 'loc' => home_url( '/' ) ) ) );
} else {
foreach ( $posts as $post ) {
$current_item = $this->post_to_news_sitemap_item( $post );

foreach ( $posts as $post ) {
$current_item = $this->post_to_news_sitemap_item( $post );

if ( false === $buffer->append( $current_item['xml'] ) ) {
break;
if ( false === $buffer->append( $current_item['xml'] ) ) {
break;
}
}
}

Expand Down

0 comments on commit 3bfae29

Please sign in to comment.