pre get posts - How to pass >= condition filter to my year custom tax_query

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 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

Share Improve this question asked Apr 2, 2019 at 20:18 anas sohailanas sohail 1 1
  • 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. – norman.lol Commented Apr 2, 2019 at 20:24
Add a comment  | 

1 Answer 1

Reset to default 0

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)
        )
     )
);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745631480a4637136.html

相关推荐

  • pre get posts - How to pass >= condition filter to my year custom tax_query

    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

    22天前
    90

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信