Search code examples
filteringjekyllblogs

Does Jekyll support searching blog posts by multiple tags?


Does Jekyll support searching blog posts by multiple tags? Based on the documentation, it seems like it supports tagging posts using multiple tags, but I'm wondering if it supports being able to filter posts using multiple tags when searching for a post


Solution

  • You can use the where filter. This code filters all posts that have the tags "jekyll" and "tutorial":

    {% assign posts = site.posts | where: "tags", "jekyll" | where: "tags", "tutorial" %}
    

    You can also use the where_exp filter:

    {% assign posts = site.posts | where_exp: "item", "item.tags contains 'jekyll' and item.tags contains 'tutorial'" %}
    

    Learn more about filters in the docs.