Make WordPress Core

Changeset 53548


Ignore:
Timestamp:
06/21/2022 01:16:10 PM (3 years ago)
Author:
audrasjb
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

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

    r52422 r53548  
    220220                'update_post_term_cache' => false,
    221221                'update_post_meta_cache' => false,
     222                'ignore_sticky_posts'    => true, // sticky posts will still appear, but they won't be moved to the front.
    222223            ),
    223224            $post_type
  • trunk/tests/phpunit/tests/sitemaps/wpSitemapsPosts.php

    r51492 r53548  
    6464
    6565    /**
     66     * Tests 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
     89    /**
    6690     * Callback for 'wp_sitemaps_posts_show_on_front_entry' filter.
    6791     */
Note: See TracChangeset for help on using the changeset viewer.