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.
$date_queryarrayrequired
...$0 arraycolumn string$default_column parameter. See WP_Date_Query::validate_column() and the 'date_query_valid_columns' filter for the list of accepted values.'post_date'.compare string'=', '!=', '>', '>=', '<', '<=', 'IN', ‘NOT IN’, 'BETWEEN', ‘NOT BETWEEN’. Default '='.relation string'OR' or 'AND'.'OR'....$0 arraybefore string|arraystrtotime()-compatible string, or array of ‘year’, ‘month’, ‘day’ values.year stringmonth stringday stringafter string|arraystrtotime()-compatible string, or array of ‘year’, ‘month’, ‘day’ values.year stringmonth stringday stringcolumn string$column parameter.$column.compare string'=', '!=', '>', '>=', '<', '<=', 'IN', ‘NOT IN’, 'BETWEEN', ‘NOT BETWEEN’. 'IN', ‘NOT IN’, 'BETWEEN', and ‘NOT BETWEEN’. Comparisons support arrays in some time-related parameters. Default '='.inclusive bool'before' or 'after'. Default false.year int|int[]$compare supports it. Default empty.month int|int[]$compare supports it. Default empty.week int|int[]$compare supports it. Default empty.dayofyear int|int[]$compare supports it.day int|int[]$compare supports it. Default empty.dayofweek int|int[]$compare supports it.dayofweek_iso int|int[]$compare supports it.hour int|int[]$compare supports it. Default empty.minute int|int[]$compare supports it. Default empty.second int|int[]$compare supports it. Default empty.$default_columnstringoptional
'post_date'.Default:'post_date'
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 );
}
You must log in before being able to contribute a note or feedback.
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_date_query/__construct