Created
March 3, 2015 00:05
-
-
Save mmikkel/c6a89a975c0e48f9d560 to your computer and use it in GitHub Desktop.
Find entries w/ category relation in Matrix block (Craft CMS)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# Fetch the category "myCategory" (and any child categories as well) #} | |
{% set categories = craft.categories.slug( 'myCategory' ) %} | |
{# Search for entries in section "test", that has the category "myCategory" (or any of its child categories) selected in the field "category" of the Matrix block "testMatrix" #} | |
{% set entries = craft.entries.section( 'test' ).relatedTo({ | |
targetElement: categories, | |
field: 'testMatrix.category' | |
}) %} | |
{# Output the entries #} | |
{% for entry in entries %} | |
{{ entry.title }}<br/> | |
{% endfor %} | |
{# Output the categories we filtered against, too #} | |
{% for category in categories %} | |
{{ category.title }} | |
{% endfor %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works perfectly !!! Thank you so much!