admin管理员组文章数量:1026144
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
1 Answer
Reset to default 0You 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)
)
)
);
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
1 Answer
Reset to default 0You 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)
)
)
);
本文标签: pre get postsHow to pass gt condition filter to my year custom taxquery
版权声明:本文标题:pre get posts - How to pass >= condition filter to my year custom tax_query 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745631478a2160191.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论