admin管理员组文章数量:1289537
I've two category employee and full-time. If a post publish in both (employee and full-time) category then the post will show in his specific section. If post has only employee category, not full-time or has only full-time, not employee, then this post will not show in the post block.
How can I do this? What will be the query of this relationship between two category??
Here is my code -
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => array('employee', 'full-time'),
)
)
Please help me to figure it out.
I've also tried with this method, but it's not working anymore. I've the same issue. Go here for better understand understand my problem - Query only Posts from Both of Two Category?
I've two category employee and full-time. If a post publish in both (employee and full-time) category then the post will show in his specific section. If post has only employee category, not full-time or has only full-time, not employee, then this post will not show in the post block.
How can I do this? What will be the query of this relationship between two category??
Here is my code -
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => array('employee', 'full-time'),
)
)
Please help me to figure it out.
I've also tried with this method, but it's not working anymore. I've the same issue. Go here for better understand understand my problem - Query only Posts from Both of Two Category?
Share Improve this question asked Aug 1, 2021 at 16:34 user209688user209688 2 |1 Answer
Reset to default 0So you want to show only posts that have both employee
and full-time
categories.
If that is the case than you can do the following.
Because you haven't posted the full query args I will only show the tax_query
part
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'employee',
),
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'full-time',
)
)
This should do the trick
本文标签: wp queryShow posts from two specific category in WPQuery
版权声明:本文标题:wp query - Show posts from two specific category in WP_Query 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741403348a2376801.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
slug
really the field name? – shanebp Commented Aug 1, 2021 at 18:18'operator' => 'AND'
in the taxonomy query clause, so have you tried adding that right below the'terms' => array(...)
line? – Sally CJ Commented Aug 2, 2021 at 9:34