Help with query conditions for search page and sub categories

I’m adding addtional sub categories to my products and can’t quite seem to figure out the conditional logic in the query.

I basically want to view all products. and then if I filted the primary category it should show all in that category, and then once I pick the secondary category it should filter and show all. I can get this to all work properly. its just that when I add the next category I can’t get it to filter correctly. I’m confused on the logic here. Here is a video of the page with the first two categories working as it should.

And here is the conditions from the query statement

So that all works for two categories but once I try to add the third and eventually 4th sub categories, I’m lost on the logic. Any advice? I’d post some of my other attempts at the conditions but I just can’t seem to get it worked out. I must be missing something here that is simple or I need to nest if statements or something?

Community Page
Last updated: