Get every year that has valid posts in a range
public static check_year_has_posts ( ) : int[] | ||
Résultat | int[] | years with posts |
/** * Generate full sitemap for site * * @subcommand generate-sitemap */ function generate_sitemap($args, $assoc_args) { $this->command = 'all'; $all_years_with_posts = Metro_Sitemap::check_year_has_posts(); $sitemap_args = array(); foreach ($all_years_with_posts as $year) { if ($this->halt_execution()) { delete_option('msm_stop_processing'); break; } $sitemap_args['year'] = $year; $this->generate_sitemap_for_year(array(), $sitemap_args); } }
/** * Generate full sitemap */ public static function generate_full_sitemap() { global $wpdb; $is_partial_or_running = get_option('msm_years_to_process'); if (empty($is_partial_or_running)) { $all_years_with_posts = Metro_Sitemap::check_year_has_posts(); update_option('msm_years_to_process', $all_years_with_posts); } else { $all_years_with_posts = $is_partial_or_running; } if (0 == count($all_years_with_posts)) { return; } // Cannot generate sitemaps if there are no posts $time = time(); $next_year = end($all_years_with_posts); wp_schedule_single_event($time, 'msm_cron_generate_sitemap_for_year', array(array('year' => (int) $next_year))); }