public static function get_last_modified_posts() { global $wpdb; $sitemap_last_run = get_option('msm_sitemap_update_last_run', false); $date = date('Y-m-d H:i:s', current_time('timestamp', 1) - 3600); // posts changed within the last hour if ($sitemap_last_run) { $date = date('Y-m-d H:i:s', $sitemap_last_run); } $post_types_in = self::get_supported_post_types_in(); $modified_posts = $wpdb->get_results($wpdb->prepare("SELECT ID, post_date FROM {$wpdb->posts} WHERE post_type IN ( {$post_types_in} ) AND post_modified_gmt >= %s ORDER BY post_date LIMIT 1000", $date)); return $modified_posts; }
/** * Generates sitemaps from the latest posts. * * Hooked into the msm_sitemap_actions-generate_from_latest action */ public static function action_generate_from_latest() { $last_modified = Metro_Sitemap::get_last_modified_posts(); if (count($last_modified) > 0) { Metro_Sitemap::update_sitemap_from_modified_posts(); Metro_Sitemap::show_action_message(__('Updating sitemap from latest articles...', 'metro-sitemaps')); } else { Metro_Sitemap::show_action_message(__('Cannot generate from latest articles: no posts updated lately.', 'metro-sitemaps'), 'error'); } }