Tribe__Tickets__Commerce__PayPal__Order::find_by( array $args = array(), null|array $fields = null )

Finds orders by a list of criteria.


Parameters

$args

(array) (Optional) Arguments to retrieve orders. See WP_Query::parse_query() for all available arguments

Default value: array()

$fields

(null|array) (Optional) List of fields to hydrate, or null for all.

Default value: null


Top ↑

Return

(Tribe__Tickets__Commerce__PayPal__Order[])


Top ↑

Source

File: src/Tribe/Commerce/PayPal/Order.php

	public static function find_by( array $args = array() ) {
		$args = wp_parse_args( $args, array(
			'post_type'   => Tribe__Tickets__Commerce__PayPal__Main::ORDER_OBJECT,
			'post_status' => 'any',
			'meta_key'    => self::$meta_prefix . 'payment_date',
			'meta_type'   => 'DATETIME',
			'order'       => 'DESC',
			'orderby'     => 'meta_value',
		) );

		global $wpdb;

		$cache     = new Tribe__Cache;
		$cache_key = self::cache_prefix( 'find_by_' . $cache->make_key( $args ) );

		if ( false !== $cached = $cache[ $cache_key ] ) {
			return $cached;
		}

		$meta_query = isset( $args['meta_query'] )
			? $args['meta_query']
			: array( 'relation' => 'AND' );

		if ( ! empty( $args['post_id'] ) ) {
			$related_post_ids              = is_array( $args['post_id'] ) ? $args['post_id'] : array( $args['post_id'] );
			$meta_query['related_post_id'] = array(
				'key'     => self::$meta_prefix . 'post',
				'value'   => $related_post_ids,
				'compare' => 'IN',
			);
			unset( $args['post_id'] );
		}

		if ( ! empty( $args['ticket_id'] ) ) {
			$related_ticket_ids              = is_array( $args['ticket_id'] ) ? $args['ticket_id'] : array( $args['ticket_id'] );
			$meta_query['related_ticket_id'] = array(
				'key'     => self::$meta_prefix . 'ticket',
				'value'   => $related_ticket_ids,
				'compare' => 'IN',
			);
			unset( $args['ticket_id'] );
		}

		if ( ! empty( $meta_query ) ) {
			$args['meta_query'] = $meta_query;
		}

		$args['fields'] = 'ids';

		$found = get_posts( $args );

		if ( $found ) {
			foreach ( $found as $order_post_id ) {
				$order    = new self();
				$orders[] = $order->hydrate_from_post( $order_post_id );
			}
		} else {
			$orders = array();
		}

		$cache[ $cache_key ] = $orders;

		return $orders;
	}

Top ↑

Changelog

Changelog
Version Description
4.7 Introduced.