\WP_Stager_Integration\Event::get_event_post_by_id(int $event_id): null|\WP_Post

Description

Gets an event post object by its Stager event ID.

Parameters:

ParameterTypeDescription
$event_id int The Stager event ID.

Returns:

null|\WP_Post Null if no event was found, the post object otherwise.

Information

Fileclass-event.php line 837

Full Code

/**
 * Gets an event post object by its Stager event ID.
 *
 * @param int $event_id The Stager event ID.
 *
 * @return null|\WP_Post    Null if no event was found, the post object otherwise.
 */
public static function get_event_post_by_id( $event_id ) {

    // Bail if invalid event ID was passed
    if ( (string) $event_id !== (string) intval( $event_id ) ) {
        return null;
    }

    // Type casting
    $event_id = (int) $event_id;

    // Get data
    $all_event_ids = (array) (self::get_event_post_ids() ?: array());
    $event_post_id = ($all_event_ids[ $event_id ] ?? null);

    // Return null if no event was found
    if ( ! $event_post_id ) {
        return null;
    }

    // Return post or null if no post was found
    return (get_post( $event_post_id ) ?: null);
}

💡 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!