ActionScheduler_wpPostStore::get_actions_by_group()protectedWC 1.0

Get IDs of actions within a certain group and up to a certain date/time.

Method of the class: ActionScheduler_wpPostStore{}

No Hooks.

Return

Array. IDs of actions in the appropriate group and before the appropriate time.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_actions_by_group( $group, $limit, $date );
$group(string) (required)
The group to use in finding actions.
$limit(int) (required)
The number of actions to retrieve.
$date(DateTime) (required)
DateTime object representing cutoff time for actions. Actions retrieved will be up to and including this DateTime.

ActionScheduler_wpPostStore::get_actions_by_group() code WC 8.7.0

protected function get_actions_by_group( $group, $limit, DateTime $date ) {
	// Ensure the group exists before continuing.
	if ( ! term_exists( $group, self::GROUP_TAXONOMY ) ) {
		/* translators: %s is the group name */
		throw new InvalidArgumentException( sprintf( __( 'The group "%s" does not exist.', 'woocommerce' ), $group ) );
	}

	// Set up a query for post IDs to use later.
	$query      = new WP_Query();
	$query_args = array(
		'fields'           => 'ids',
		'post_type'        => self::POST_TYPE,
		'post_status'      => ActionScheduler_Store::STATUS_PENDING,
		'has_password'     => false,
		'posts_per_page'   => $limit * 3,
		'suppress_filters' => true,
		'no_found_rows'    => true,
		'orderby'          => array(
			'menu_order' => 'ASC',
			'date'       => 'ASC',
			'ID'         => 'ASC',
		),
		'date_query'       => array(
			'column'    => 'post_date_gmt',
			'before'    => $date->format( 'Y-m-d H:i' ),
			'inclusive' => true,
		),
		'tax_query'        => array( // phpcs:ignore WordPress.DB.SlowDBQuery
			array(
				'taxonomy'         => self::GROUP_TAXONOMY,
				'field'            => 'slug',
				'terms'            => $group,
				'include_children' => false,
			),
		),
	);

	return $query->query( $query_args );
}