Esclude old post from sitemap: works but sitemap index display the sitemap blank
-
Hi all,
I want to exclude all post older then the last 2 years in my YOAST sitemap.
I use the wpseo_exclude_from_sitemap_by_post_ids filter to do that.function exclude_posts_from_xml_sitemaps() { global $wpdb; /*$date = new DateTime('first day of this year'); $date_str = $date->format('Y-m-d H:i:s');*/ $date_str = '2018-01-31 00:00:00'; $query = " SELECT ID FROM $wpdb->posts WHERE post_date < '$date_str' AND post_type = 'post' ORDER BY post_date DESC"; $results = $wpdb->get_results($query); foreach ($results as $result) { $array[] = $result->ID; } return $array; } add_filter('wpseo_exclude_from_sitemap_by_post_ids', 'exclude_posts_from_xml_sitemaps');
All works fine but sitemap_index.xml still display some (empty) post-sitemap1.xml post-sitemap2.xm etc.
Seems like the main sitemap not check if content of related sub post-sitemap is greater then 0 before add it.
Some suggestion?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Esclude old post from sitemap: works but sitemap index display the sitemap blank’ is closed to new replies.