Filters the post type sitemaps in XML Sitemap Index context when the sitemaps Server is set to Plugin.
apply_filters( 'xmlsf_index_archive_data', array[] $data , string[] $post_type, string[] $archive_type )
Used in xml-sitemap-feed/views/feed-sitemap.php
Parameters (3)
- $data
(array)
The original set of sitemaps. An array of URL and lastmod date pairs. - $post_type
(string) The post type, one of:post|page
or a custom post type slug. - $archive_type
(string)
The current archive type, one of:yearly|monthly|weekly
Return
(array)
An array of URL and lastmod date pairs.
Must return an array of URL and lastmod date pairs. When hooked before priority 10, the original $data will be empty.
Usage example
function my_remove_old_sitemaps( $data, $post_type = 'post', $archive_type ) {
if ( 'post' !== $post_type || empty( $archive_type) ) {
return $data;
}
// Set year archive sitemaps to remove.
$remove = array( '2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019' );
foreach ( $data as $d_key => $d_value ) {
foreach ( $remove as $year ) {
if ( strpos( $d_key, '.' . $year ) ) {
unset( $data[ $d_key ] );
}
}
}
return $data;
}
add_filter( 'xmlsf_index_archive_data', 'my_remove_old_sitemaps', 11, 3 );
Related
Used by | Description |
---|---|
Sitemap_Plugin::index_archive_data() | Fetches post archives data from cache or database. |