Automattic\WooCommerce\Internal\Admin\Reports

ProductSearchQuery::build_statement │ private static │ WC 1.0

Returns the statement WP_Query builds for the given arguments, without running it.

The search composes into the report query, so the statement is what is needed rather than the rows. Going through WP_Query keeps the query filters in play, which is how multilingual plugins restrict products to the active language and how the search box itself resolves a term.

Метод класса: ProductSearchQuery{}

Хуков нет.

Возвращает

string. SQL statement.

Использование

$result = ProductSearchQuery::build_statement( $args ): string;
$args(массив) (обязательный)
Query arguments.

Код ProductSearchQuery::build_statement() WC 11.2.2

private static function build_statement( array $args ): string {
	add_filter( 'posts_join', array( __CLASS__, 'add_wp_query_join' ), 10, 2 );
	add_filter( 'posts_where', array( __CLASS__, 'add_wp_query_filter' ), 10, 2 );
	add_filter( 'posts_pre_query', array( __CLASS__, 'skip_wp_query_results' ), 10, 2 );

	try {
		$query = new WP_Query();
		$query->query( $args );

		return $query->request;
	} finally {
		// A filter left behind would follow every later query in the request, so drop them
		// even when the query above threw.
		remove_filter( 'posts_join', array( __CLASS__, 'add_wp_query_join' ), 10 );
		remove_filter( 'posts_where', array( __CLASS__, 'add_wp_query_filter' ), 10 );
		remove_filter( 'posts_pre_query', array( __CLASS__, 'skip_wp_query_results' ), 10 );
	}
}