I have a custom taxonomy called year. I need to filter posts by pre_get_posts tax_query from year value to to year value. I am searching from one hour now feeling stuck. Please guide me.
Thank you
I have a custom taxonomy called year. I need to filter posts by pre_get_posts tax_query from year value to to year value. I am searching from one hour now feeling stuck. Please guide me.
Thank you
You can pass an array of years to the tax_query (or use PHP range()). The default operator is IN
- see https://developer.wordpress/reference/classes/wp_tax_query/__construct/#parameters
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'year',
'field' => 'name',
'terms' => range($min_year, $max_year)
)
)
);