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

  • 1
    Welcome to WordPress StackExchange! Please read How do I ask a good question and update your question accordingly. We need a reproducible and narrowly-scoped question. We need to know what exactly you've tried so far and where exactly you are stuck. For example would it be necessary to include your current query into your question.
    – leymannx
    Apr 2 '19 at 20:24

You can pass an array of years to the tax_query (or use PHP range()). The default operator is IN - see https://developer.wordpress.org/reference/classes/wp_tax_query/__construct/#parameters

$args = array(
    'tax_query' => array(
           'taxonomy' => 'year',
           'field' => 'name',
           'terms' => range($min_year, $max_year)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.