Searching for blogpost based on tags

For the General Blog Layout, I used the code on the helpful Docs Demo Site so that visitors could search for posts based on a tag topic.
https://docs.treepl.co/demo-custom-blog
This works beautifully except, I’ve just discovered, for tags with two or more words and therefore containing spaces. This is because spaces are removed when the tag is passed to the URL. For example, if I click on the tag “awesome topic” the URL returned is:
/blog?tag=awesometopic
and no results are shown. But if I manually add the coding for a space to the URL
/blog?tag=awesome%20topic
results will appear.

We are now replacing spaces with underscores in our tags to fix this.
@Adam.Wilson maybe a note could be added to the Docs to warn about potential pitfalls of using spaces in tags.

Hi @hopestew. The demo blog has a tag with spaces and it works fine.
This is achieved by using the filter | url_encode to generate the tag link appropriate for use in the URL.
I’m guessing your implementation might be missing this… I’m not sure?

1 Like

@Adam.Wilson as usual you are on the ball. I should have check my code more thoroughly before posting. Thanks for your quick reply!

1 Like