<?php

namespace Waypoint\Agent\Helpers;

class Posts {

	public static function find_by_external_id( string $external_id ): ?\WP_Post {
		$posts = get_posts( [
			'post_type'      => 'any',
			'post_status'    => 'any',
			'posts_per_page' => 1,
			'meta_query'     => [
				[
					'key'   => '_waypoint_external_id',
					'value' => $external_id,
				],
			],
		] );
		return ! empty( $posts ) ? $posts[0] : null;
	}
}
