3

I want to only show entries that match a specific tag. I'm trying to do something like:

{% paginate craft.entries.section('blog').relatedTo('tagName').order('score') as entriesOnPage %}

This doesn't seem to net any results though. Is .relatedTo() not the way to go when limiting results to a specific tag?

5

You'd need to get the tag model first.

{% set tag = craft.tags.search('My Tag').first() %}
{% if tag %}
    {% set entries = craft.entries.relatedTo(tag) %}
{% endif %}

Replace search with whatever other information you have from the tag, to get more precise results, e.g., slug, id properties.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.