From ea94b5c5cd08893b06d589367d9023eeabb67f8f Mon Sep 17 00:00:00 2001
From: Paul Biron <paul@sparrowhawkcomputing.com>
Date: Sat, 28 May 2022 12:56:37 -0600
Subject: [PATCH] Ignore sticky posts by default in post sitemaps.
---
.../providers/class-wp-sitemaps-posts.php | 1 +
.../tests/sitemaps/wpSitemapsPosts.php | 24 +++++++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/src/wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php b/src/wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php
index 61dffdbd79..b9f2fd3185 100644
a
|
b
|
class WP_Sitemaps_Posts extends WP_Sitemaps_Provider { |
219 | 219 | 'no_found_rows' => true, |
220 | 220 | 'update_post_term_cache' => false, |
221 | 221 | 'update_post_meta_cache' => false, |
| 222 | 'ignore_sticky_posts' => true, // sticky posts will still appear, but they won't be moved to the front. |
222 | 223 | ), |
223 | 224 | $post_type |
224 | 225 | ); |
diff --git a/tests/phpunit/tests/sitemaps/wpSitemapsPosts.php b/tests/phpunit/tests/sitemaps/wpSitemapsPosts.php
index b60903e18a..fe2859bafc 100644
a
|
b
|
class Tests_Sitemaps_wpSitemapsPosts extends WP_UnitTestCase { |
62 | 62 | $this->assertArrayHasKey( 'lastmod', $sitemap_entry ); |
63 | 63 | } |
64 | 64 | |
| 65 | /** |
| 66 | * Test that sticky posts are not moved to the front of the first page of the post sitemap. |
| 67 | * |
| 68 | * @ticket 55633 |
| 69 | */ |
| 70 | public function test_posts_sticky_posts() { |
| 71 | $factory = self::factory(); |
| 72 | |
| 73 | // Create 4 posts, and stick the last one. |
| 74 | $post_ids = $factory->post->create_many( 4 ); |
| 75 | $last_post_id = end( $post_ids ); |
| 76 | stick_post( $last_post_id ); |
| 77 | |
| 78 | $posts_provider = new WP_Sitemaps_Posts(); |
| 79 | |
| 80 | $url_list = $posts_provider->get_url_list( 1, 'post' ); |
| 81 | |
| 82 | $this->assertCount( count( $post_ids ), $url_list ); |
| 83 | // Check that the URL list is still in the order of the post IDs (i.e., sticky post wasn't moved to the front). |
| 84 | foreach ( $post_ids as $idx => $post_id ) { |
| 85 | $this->assertSame( array( 'loc' => home_url( "?p={$post_id}" ) ), $url_list[ $idx ] ); |
| 86 | } |
| 87 | } |
| 88 | |
65 | 89 | /** |
66 | 90 | * Callback for 'wp_sitemaps_posts_show_on_front_entry' filter. |
67 | 91 | */ |