From d91e14845295baf7891d88577b73631f69040423 Mon Sep 17 00:00:00 2001 From: Jb Audras Date: Tue, 21 Jun 2022 13:16:10 +0000 Subject: [PATCH] Sitemaps: Remove duplicate sticky Posts from Sitemap Post Query. This changeset sets the `ignore_sticky_posts` parameter to `true` in the default arguments passed to `wp_sitemaps_posts_query_args`. Props RavanH, pbiron, swissspidy, audrasjb, SergeyBiryukov. Fixes #55633. git-svn-id: https://develop.svn.wordpress.org/trunk@53548 602fd350-edb4-49c9-b593-d223f7449a82 --- .../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/src/wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php +++ b/src/wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php @@ -219,6 +219,7 @@ class WP_Sitemaps_Posts extends WP_Sitemaps_Provider { 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, + 'ignore_sticky_posts' => true, // sticky posts will still appear, but they won't be moved to the front. ), $post_type ); diff --git a/tests/phpunit/tests/sitemaps/wpSitemapsPosts.php b/tests/phpunit/tests/sitemaps/wpSitemapsPosts.php index b60903e18a..cf400c4177 100644 --- a/tests/phpunit/tests/sitemaps/wpSitemapsPosts.php +++ b/tests/phpunit/tests/sitemaps/wpSitemapsPosts.php @@ -62,6 +62,30 @@ class Tests_Sitemaps_wpSitemapsPosts extends WP_UnitTestCase { $this->assertArrayHasKey( 'lastmod', $sitemap_entry ); } + /** + * Tests that sticky posts are not moved to the front of the first page of the post sitemap. + * + * @ticket 55633 + */ + public function test_posts_sticky_posts() { + $factory = self::factory(); + + // Create 4 posts, and stick the last one. + $post_ids = $factory->post->create_many( 4 ); + $last_post_id = end( $post_ids ); + stick_post( $last_post_id ); + + $posts_provider = new WP_Sitemaps_Posts(); + + $url_list = $posts_provider->get_url_list( 1, 'post' ); + + $this->assertCount( count( $post_ids ), $url_list ); + // Check that the URL list is still in the order of the post IDs (i.e., sticky post wasn't moved to the front). + foreach ( $post_ids as $idx => $post_id ) { + $this->assertSame( array( 'loc' => home_url( "?p={$post_id}" ) ), $url_list[ $idx ] ); + } + } + /** * Callback for 'wp_sitemaps_posts_show_on_front_entry' filter. */