Skip to content

Commit 304ed9f

Browse files
committed
Exclude canonicalized objects from sitemap
1 parent d0f48d7 commit 304ed9f

4 files changed

Lines changed: 7 additions & 2 deletions

inc/sitemaps/abstract-class-indexable-sitemap-provider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ protected function get_last_object_per_page( $max_entries_per_page ) {
100100
$query = $this->repository
101101
->query_where_noindex( false, $this->get_object_type() )
102102
->select_many( 'id', 'object_sub_type' )
103+
->where_raw( '( `canonical` IS NULL OR `canonical` = `permalink` )' )
103104
->order_by_asc( 'object_sub_type' )
104105
->order_by_asc( 'object_last_modified' );
105106

@@ -149,6 +150,7 @@ protected function get_last_object_per_page( $max_entries_per_page ) {
149150
->select( 'object_sub_type' )
150151
->select_expr( 'MAX(`object_last_modified`)', 'post_type_last_modified' )
151152
->select_expr( 'COUNT(`id`)', 'number_of_posts' )
153+
->where_raw( '( `canonical` IS NULL OR `canonical` = `permalink` )' )
152154
->having_gt( 'number_of_posts', 0 )
153155
->group_by( 'object_sub_type' );
154156

inc/sitemaps/class-author-sitemap-provider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ public function handles_type( $type ) {
6060
* @return array
6161
*/
6262
public function get_index_links( $max_entries ) {
63-
global $wpdb;
64-
6563
if ( ! $this->handles_type( 'author' ) ) {
6664
return [];
6765
}
@@ -111,6 +109,7 @@ public function get_sitemap_links( $type, $max_entries, $current_page ) {
111109
$query = $this->repository
112110
->query_where_noindex( false, 'user', null, $noindex_authors_with_no_posts )
113111
->select_many( 'id', 'object_id', 'permalink', 'object_last_modified' )
112+
->where_raw( '( `canonical` IS NULL OR `canonical` = `permalink` )' )
114113
->order_by_asc( 'object_last_modified' )
115114
->offset( $offset )
116115
->limit( $max_entries );
@@ -145,6 +144,7 @@ protected function get_last_object_per_page( $max_entries_per_page ) {
145144
$query = $this->repository
146145
->query_where_noindex( false, 'user', null, $noindex_authors_with_no_posts )
147146
->select( 'id' )
147+
->where_raw( '( `canonical` IS NULL OR `canonical` = `permalink` )' )
148148
->order_by_asc( 'object_last_modified' );
149149

150150
$users_to_exclude = $this->exclude_users();
@@ -185,6 +185,7 @@ protected function get_last_object_per_page( $max_entries_per_page ) {
185185
->query_where_noindex( false, 'user', null, $noindex_authors_with_no_posts )
186186
->select_expr( 'MAX(`object_last_modified`)', 'most_recently_modified' )
187187
->select_expr( 'COUNT(`id`)', 'number_of_authors' )
188+
->where_raw( '( `canonical` IS NULL OR `canonical` = `permalink` )' )
188189
->having_gt( 'number_of_authors', 0 );
189190

190191
if ( is_array( $users_to_exclude ) && count( $users_to_exclude ) > 0 ) {

inc/sitemaps/class-post-type-sitemap-provider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public function get_sitemap_links( $type, $max_entries, $current_page ) {
8282
$query = $this->repository
8383
->query_where_noindex( false, 'post', $type )
8484
->select_many( 'id', 'object_id', 'permalink', 'object_last_modified' )
85+
->where_raw( '( `canonical` IS NULL OR `canonical` = `permalink` )' )
8586
->order_by_asc( 'object_last_modified' )
8687
->offset( $offset )
8788
->limit( $max_entries );

inc/sitemaps/class-taxonomy-sitemap-provider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public function get_sitemap_links( $type, $max_entries, $current_page ) {
102102
$query = $this->repository
103103
->query_where_noindex( false, 'term', $type )
104104
->select_many( 'id', 'object_id', 'permalink', 'object_last_modified' )
105+
->where_raw( '( `canonical` IS NULL OR `canonical` = `permalink` )' )
105106
->order_by_asc( 'object_last_modified' )
106107
->offset( $offset )
107108
->limit( $steps );

0 commit comments

Comments
 (0)