WordPress 3.7 introduced ‘date_query’ argument for WP_Query
.
That’s pretty useful and allow very complex date-based queries, however something strange happen when using WP_Query
conditional methods on query using that argument.
Example:
$args = array(
'tax_query'=> array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'uncategorized'
),
array(
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => array('foo', 'bar')
)
),
'date_query' => array(
array(
'year' => $today["year"],
'month' => $today["mon"],
'day' => $today["mday"],
)
)
);
$query = new WP_Query( $args );
The query should returns posts posted today and having ‘uncategorized’ category or ‘foo’ and ‘bar’ tags. And it does, so far so good.
Now consider the following conditional methods:
$query->is_archive(); // returns true, as guessable
$query->is_category(); // returns true, as guessable
$query->is_tag(); // returns true, as guessable
but
$query->is_date(); // returns false
$query->is_day(); // returns false
$query->is_month(); // returns false
$query->is_year(); // returns false
I thought that the problem can be caused by the fact I mixed ‘tax_query’ and ‘date_query’, but that’s not the problem, proof:
$args = array(
'date_query' => array(
array(
'year' => $today["year"],
'month' => $today["mon"],
'day' => $today["mday"],
)
)
);
$query = new WP_Query( $args );
$query->is_date(); // returns false
$query->is_day(); // returns false
$query->is_month(); // returns false
$query->is_year(); // returns false
$query->is_archive(); // returns false this time
Is this a bug, or I’m missing something? (I’ve searched WP Trac, but found nothing related).