Metro_Sitemap::date_range_has_posts PHP Method

date_range_has_posts() public static method

Does a current date range have posts?
public static date_range_has_posts ( string $start_date, string $end_date ) : integer | false
$start_date string
$end_date string
return integer | false
    public static function date_range_has_posts($start_date, $end_date)
    {
        global $wpdb;
        $start_date .= ' 00:00:00';
        $end_date .= ' 23:59:59';
        $post_types_in = self::get_supported_post_types_in();
        return $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_status = 'publish' AND post_date >= %s AND post_date <= %s AND post_type IN ( {$post_types_in} ) LIMIT 1", $start_date, $end_date));
    }

Usage Example

function vipgo_generate_sitemap_for_year_month_day($args)
{
    $year = $args['year'];
    $month = $args['month'];
    $day = $args['day'];
    $date_stamp = Metro_Sitemap::get_date_stamp($year, $month, $day);
    if (Metro_Sitemap::date_range_has_posts($date_stamp, $date_stamp)) {
        Metro_Sitemap::generate_sitemap_for_date($date_stamp);
    } else {
        Metro_Sitemap::delete_sitemap_for_date($date_stamp);
    }
}
All Usage Examples Of Metro_Sitemap::date_range_has_posts