\WP_Stager_Integration\Event::get_events_by_day(int $timestamp): array[]

Description

Gets events for a given day (including multi-day events overlapping that day).

Parameters:

ParameterTypeDescription
$timestamp int A Unix timestamp representing the day.

Returns:

array[] List of raw Stager event arrays.

Information

Fileclass-event.php line 511

Full Code

/**
 * Gets events for a given day (including multi-day events overlapping that day).
 *
 * @param int $timestamp A Unix timestamp representing the day.
 *
 * @return array[] List of raw Stager event arrays.
 */
public static function get_events_by_day( $timestamp ) {

    global $wpdb;

    $timestamp = (int) $timestamp;
    $day_start = Calendar::calculate_timestamp_day_start( $timestamp );
    $day_end   = Calendar::calculate_timestamp_day_end( $timestamp );

    $sql = "
        SELECT pm_raw.meta_value
        FROM {$wpdb->posts} p
        JOIN {$wpdb->postmeta} pm_start
          ON p.ID = pm_start.post_id
         AND pm_start.meta_key = %s
        JOIN {$wpdb->postmeta} pm_end
          ON p.ID = pm_end.post_id
         AND pm_end.meta_key = %s
        JOIN {$wpdb->postmeta} pm_raw
          ON p.ID = pm_raw.post_id
         AND pm_raw.meta_key = %s
        WHERE p.post_type = %s
          AND p.post_status = 'publish'
          AND CAST(pm_start.meta_value AS UNSIGNED) <= %d
          AND CAST(pm_end.meta_value   AS UNSIGNED) >= %d
        ORDER BY CAST(pm_start.meta_value AS UNSIGNED) ASC
    ";

    $rows = $wpdb->get_col( $wpdb->prepare(
                    $sql,
                    self::get_meta_key( self::META_KEY_TIMESTAMP_PROGRAM_START ),
                    self::get_meta_key( self::META_KEY_TIMESTAMP_PROGRAM_END ),
                    self::get_meta_key( self::META_KEY_RAW_DATA ),
                    self::CPT_SLUG,
                    $day_end,
                    $day_start
            ) );

    // Get events
    $events = (array) (array_map( 'maybe_unserialize', $rows ) ?: array());

    return self::parse_events( $events );
}

💡 If you ever get stuck or have a question, please check our FAQs, our Free Integration Service, our paid Full Integration Service, or reach out to us!

Get WP Stager Integration

🎁 Limited offer: Use code WELCOME26 to get your first month for free!