I think this sentence threw me off the same way it threw off Jhoanne. I interpreted it as meaning that you were looking to display any post that has more than one category, not that you were looking for posts that had two specific categories associated with it. The latter is simple, the former requires the more complex syntax that Jhoanne came up with.
There are a ton of query parameters you can use to adjust a post loop. The category
query parameter is great when you just want to display posts in certain categories, like category=firstcategory,secondcategory
. Or if you wanted one of those categories to be filled in dynamically, the syntax would be category="{Route part=1},extra"
. But these just use “or” logic as you’d noticed.
If you want more control than what the simple category
parameter gives you, you’ll want to use the taxonomy
, taxonomy_compare
, terms
, and taxonomy_relation
parameters. Those give you a ton more control when you want to display posts that match specific categories using certain logic. You’ll probably be able to figure out how those work from looking at the docs linked above, but let me know if you get stuck.
Minor note for @Sunskie, if you want to add multiple values to an attribute, there’s no need to create a list variable and render it in the attribute value. You can just write it out with a comma-separated list in the value, just like you would in HTML. So something like category="CategoryX,CategoryY"
in your example. Edit: I just realized that arrays aren’t a thing in HTML but they’re a thing in other languages like javascript. I should probably add an explanation about what arrays are to the docs so people who only know HTML are made aware that that’s a thing.