WP_Date_Query::__construct()publicWP 3.7.0

Constructor.

Time-related parameters that normally require integer values ('year', 'month', 'week', 'dayofyear', 'day', 'dayofweek', 'dayofweek_iso', 'hour', 'minute', 'second') accept arrays of integers for some values of 'compare'. When 'compare' is 'IN' or 'NOT IN', arrays are accepted; when 'compare' is 'BETWEEN' or 'NOT BETWEEN', arrays of two valid values are required. See individual argument descriptions for accepted values.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

$WP_Date_Query = new WP_Date_Query();
$WP_Date_Query->__construct( $date_query, $default_column );
$date_query(массив) (обязательный)

Array of date query clauses.

  • ...$0(массив)

    • column(строка)
      Optional. The column to query against. If undefined, inherits the value of the $default_column parameter. See WP_Date_Query::validate_column() and the {@see 'date_query_valid_columns'} filter for the list of accepted values.
      По умолчанию: 'post_date'

    • compare(строка)
      Optional. The comparison operator. Accepts '=', '!=', '>', '>=', '<', '<=', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'.
      По умолчанию: '='

    • relation(строка)
      Optional. The boolean relationship between the date queries. Accepts 'OR' or 'AND'.
      По умолчанию: 'OR'

    • ...$0(массив)
      Optional. An array of first-order clause parameters, or another fully-formed date query.

      • before(строка|массив)
        Optional. Date to retrieve posts before. Accepts strtotime()-compatible string, or array of 'year', 'month', 'day' values.

        • year(строка)
          The four-digit year. Accepts any four-digit year.
          По умолчанию: ''

        • month(строка)
          Optional when passing array.The month of the year. Accepts numbers 1-12.
          По умолчанию: (string:empty)|(array:1)

        • day(строка)
          Optional when passing array.The day of the month. Accepts numbers 1-31.
          По умолчанию: (string:empty)|(array:1)
      • after(строка|массив)
        Optional. Date to retrieve posts after. Accepts strtotime()-compatible string, or array of 'year', 'month', 'day' values.

        • year(строка)
          The four-digit year. Accepts any four-digit year.
          По умолчанию: ''

        • month(строка)
          Optional when passing array. The month of the year. Accepts numbers 1-12.
          По умолчанию: (string:empty)|(array:12)

        • day(строка)
          Optional when passing array.The day of the month. Accepts numbers 1-31.
          По умолчанию: (string:empty)|(array:last day of month)
      • column(строка)
        Optional. Used to add a clause comparing a column other than the column specified in the top-level $column parameter. See WP_Date_Query::validate_column() and the {@see 'date_query_valid_columns'} filter for the list of accepted values.
        По умолчанию: value of top-level $column

      • compare(строка)
        Optional. The comparison operator. Accepts '=', '!=', '>', '>=', '<', '<=', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'. 'IN', 'NOT IN', 'BETWEEN', and 'NOT BETWEEN'. Comparisons support arrays in some time-related parameters.
        По умолчанию: '='

      • inclusive(true|false)
        Optional. Include results from dates specified in 'before' or 'after'.
        По умолчанию: false

      • year(int|int[])
        Optional. The four-digit year number. Accepts any four-digit year or an array of years if $compare supports it.
        По умолчанию: ''

      • month(int|int[])
        Optional. The two-digit month number. Accepts numbers 1-12 or an array of valid numbers if $compare supports it.
        По умолчанию: ''

      • week(int|int[])
        Optional. The week number of the year. Accepts numbers 0-53 or an array of valid numbers if $compare supports it.
        По умолчанию: ''

      • dayofyear(int|int[])
        Optional. The day number of the year. Accepts numbers 1-366 or an array of valid numbers if $compare supports it.

      • day(int|int[])
        Optional. The day of the month. Accepts numbers 1-31 or an array of valid numbers if $compare supports it.
        По умолчанию: ''

      • dayofweek(int|int[])
        Optional. The day number of the week. Accepts numbers 1-7 (1 is Sunday) or an array of valid numbers if $compare supports it.
        По умолчанию: ''

      • dayofweek_iso(int|int[])
        Optional. The day number of the week (ISO). Accepts numbers 1-7 (1 is Monday) or an array of valid numbers if $compare supports it.
        По умолчанию: ''

      • hour(int|int[])
        Optional. The hour of the day. Accepts numbers 0-23 or an array of valid numbers if $compare supports it.
        По умолчанию: ''

      • minute(int|int[])
        Optional. The minute of the hour. Accepts numbers 0-59 or an array of valid numbers if $compare supports it.
        По умолчанию: ''

      • second(int|int[])
        Optional. The second of the minute. Accepts numbers 0-59 or an array of valid numbers if $compare supports it.
        По умолчанию: ''
$default_column(строка)
See WP_Date_Query::validate_column() and the date_query_valid_columns filter for the list of accepted values. Default 'post_date'.
По умолчанию: column to query against

Список изменений

С версии 3.7.0 Введена.
С версии 4.0.0 The $inclusive logic was updated to include all times within the date range.
С версии 4.1.0 Introduced 'dayofweek_iso' time type parameter.

Код WP_Date_Query::__construct() WP 6.6.2

public function __construct( $date_query, $default_column = 'post_date' ) {
	if ( empty( $date_query ) || ! is_array( $date_query ) ) {
		return;
	}

	if ( isset( $date_query['relation'] ) ) {
		$this->relation = $this->sanitize_relation( $date_query['relation'] );
	} else {
		$this->relation = 'AND';
	}

	// Support for passing time-based keys in the top level of the $date_query array.
	if ( ! isset( $date_query[0] ) ) {
		$date_query = array( $date_query );
	}

	if ( ! empty( $date_query['column'] ) ) {
		$date_query['column'] = esc_sql( $date_query['column'] );
	} else {
		$date_query['column'] = esc_sql( $default_column );
	}

	$this->column = $this->validate_column( $this->column );

	$this->compare = $this->get_compare( $date_query );

	$this->queries = $this->sanitize_query( $date_query );
}