Automattic\WooCommerce\Blocks\BlockTypes\ProductCollection
QueryBuilder::get_date_query
Constructs a date query for product filtering based on a specified time frame.
Метод класса: QueryBuilder{}
Хуков нет.
Возвращает
Массив. Date query array; empty if parameters are invalid.
Использование
// private - только в коде основоного (родительского) класса $result = $this->get_date_query( $time_frame ): array;
- $time_frame(массив) (обязательный)
Associative array with
'operator'(in or not-in) and'value'(date string).-
operator(строка)
Determines the inclusion or exclusion of the date range. - value(строка)
The date around which the range is applied.
-
Код QueryBuilder::get_date_query() QueryBuilder::get date query WC 10.9.4
private function get_date_query( array $time_frame ): array {
// Validate time_frame elements.
if ( empty( $time_frame['operator'] ) || empty( $time_frame['value'] ) ) {
return array();
}
// Determine the query operator based on the 'operator' value.
$query_operator = 'in' === $time_frame['operator'] ? 'after' : 'before';
// Construct and return the date query.
return array(
'date_query' => array(
array(
'column' => 'post_date_gmt',
$query_operator => $time_frame['value'],
'inclusive' => true,
),
),
);
}