A good friend of mine emailed me today with a WordPress question:
we have a url like /category/term1/ that we’re using to filter on stuff
If I do get_query_var(‘category’) it will properly return ‘term1’
If we have the url like /category/term1+term2/
get_query_var(‘category’) still only returns ‘term1’… do you have any insight as to why?
I didn’t dig into this too deeply, but found the posts returned sort of curious. It returned
term1 only if
term2 was a valid term. If say you wrote
foobar was not a valid term, then no posts were returned. I tested this merely by seeing what the browser returned from my own blog. You’ll notice https://www.mikeauteri.com/category/code-snippets+wordpress/ will return just posts in the category term
wordpress is also a valid term on my blog), however, https://www.mikeauteri.com/category/code-snippets+foobar/ will return nothing (
foobar is NOT a valid term on my blog).
Then, just for the hell of it, I tried using a comma instead of a plus… and it did exactly what my friend was looking to do.
So https://www.mikeauteri.com/category/code-snippets,wordpress/ will return all posts for both
wordpress. If you add an invalid term (like
foobar) it will just be ignored.
Anyway, pretty neat 🙂