WordPress at a glance
function is not described

WC_API_Resource::merge_query_args() protected WC 2.1

Add common request arguments to argument list before WP_Query is run

{} It's a method of the class: WC_API_Resource{}

No Hooks.

Return

Array.

Usage

// protected - for code of main (parent) or child class
$result = $this->merge_query_args( $base_args, $request_args );
$base_args(array) (required)
required arguments for the query (e.g. post_type, etc)
$request_args(array) (required)
arguments provided in the request

Changelog

Since 2.1 Introduced.

Code of WC_API_Resource::merge_query_args() WC 5.0.0

<?php
protected function merge_query_args( $base_args, $request_args ) {

	$args = array();

	// date
	if ( ! empty( $request_args['created_at_min'] ) || ! empty( $request_args['created_at_max'] ) || ! empty( $request_args['updated_at_min'] ) || ! empty( $request_args['updated_at_max'] ) ) {

		$args['date_query'] = array();

		// resources created after specified date
		if ( ! empty( $request_args['created_at_min'] ) ) {
			$args['date_query'][] = array( 'column' => 'post_date_gmt', 'after' => $this->server->parse_datetime( $request_args['created_at_min'] ), 'inclusive' => true );
		}

		// resources created before specified date
		if ( ! empty( $request_args['created_at_max'] ) ) {
			$args['date_query'][] = array( 'column' => 'post_date_gmt', 'before' => $this->server->parse_datetime( $request_args['created_at_max'] ), 'inclusive' => true );
		}

		// resources updated after specified date
		if ( ! empty( $request_args['updated_at_min'] ) ) {
			$args['date_query'][] = array( 'column' => 'post_modified_gmt', 'after' => $this->server->parse_datetime( $request_args['updated_at_min'] ), 'inclusive' => true );
		}

		// resources updated before specified date
		if ( ! empty( $request_args['updated_at_max'] ) ) {
			$args['date_query'][] = array( 'column' => 'post_modified_gmt', 'before' => $this->server->parse_datetime( $request_args['updated_at_max'] ), 'inclusive' => true );
		}
	}

	// search
	if ( ! empty( $request_args['q'] ) ) {
		$args['s'] = $request_args['q'];
	}

	// resources per response
	if ( ! empty( $request_args['limit'] ) ) {
		$args['posts_per_page'] = $request_args['limit'];
	}

	// resource offset
	if ( ! empty( $request_args['offset'] ) ) {
		$args['offset'] = $request_args['offset'];
	}

	// resource page
	$args['paged'] = ( isset( $request_args['page'] ) ) ? absint( $request_args['page'] ) : 1;

	return array_merge( $base_args, $args );
}