0

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?

2
  • Show your whole query, not just the tax_query. And is slug really the field name?
    – shanebp
    Commented Aug 1, 2021 at 18:18
  • 1
    The accepted answer for the linked question used '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

1 Answer 1

0

So 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

1
  • Solved. Thanks a lot.
    – user209688
    Commented Aug 17, 2021 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.