Yes, I believe it’s possible using the taxonomy parameter.
[loop type="post" taxonomy="category" value="x,y" compare="and" taxonomy_2="tag" value_2="a,b,c" compare_2="not"]
[field title-link]
[/loop]
Thanx for the (quick) reply, but unfortunately it’s not working.
This:
[loop type="post" taxonomy="category" value="x,y" compare="and"]
[field title-link]
[/loop]
…doesn’t give a result to start with, while there are posts in both categories.
Perhaps you need compare=”or”. This will show posts that are in either categories. With compare=”and”, it searches for only posts that have both categories x and y.
No, the loop in my first post was giving results…
Hmm..hard to say why there’s no result.
Can you try each of these and see if they work as you expect?
[loop type="post" taxonomy="category" value="x"]
[loop type="post" taxonomy="category" value="y"]
Now, this should show posts that are in either groups..
[loop type="post" taxonomy="category" value="x,y"]
..and posts that are common to both groups.
[loop type="post" taxonomy="category" value="x,y" compare="and"]
Hopefully this will narrow down where it’s going wrong.
The last one is not giving any results. Although there are posts that appear in the first AND second loop, so there are posts common to both groups.
First loop shows posts 1,2 and 3
Second loop shows posts 1,2,3 and 4
Third loop shows posts 1,2,3 and 4
Fourth loop shows nothing and should show 1,2 and 3.
Earlier you said this was working:
[loop type="post" category="x,y" compare="and"]
So the slugs are correct and there are posts that match categories x and y – which means this should give the same result:
[loop type="post" taxonomy="category" value="x,y" compare="and"]
I tested this, and it’s working as expected. Strange why it’s not working for you.. I’m looking at the code for the taxonomy parameter, but it’s very simple, just preparing and passing parameters to WP_Query. So I don’t see anything that could give a wrong result.
I’d like to solve this, but I cannot reproduce the issue on my end. Please let me know if you find out anything more.
You’re right, the first one is giving the expected results, the second isn’t. They should give the same results.
I’ve tried something similar on another website and on that one it is working indeed as expected.
I’ve tried using the standard theme, but the problem still occurs. Disabling plugins hasn’t done anything either :-S
If if find anything out, I’ll let you know. Thanx for the support anyway!
Interesting that the two lines are giving different results. They’re actually using different parameters for WP_Query – the first one uses cat (ID) and category_name (slug), and the second one uses tax_query which accepts more complex queries. Still, the above two queries should be identical. I recall that there was some work done on taxonomy queries in the latest WP core update, so I’ll see if it could be related.