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?
Thanks
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 /category/term1+foobar/
and 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://mikeauteri.com/category/code-snippets+wordpress/ will return just posts in the category term code-snippets
(wordpress
is also a valid term on my blog), however, https://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://mikeauteri.com/category/code-snippets,wordpress/ will return all posts for both code-snippets
AND wordpress
. If you add an invalid term (like foobar
) it will just be ignored.
Anyway, pretty neat 🙂
Leave a Reply