Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc missing for filtering entries by taxonomy #1071

Closed
dadaxr opened this issue Jun 22, 2023 · 0 comments
Closed

doc missing for filtering entries by taxonomy #1071

dadaxr opened this issue Jun 22, 2023 · 0 comments

Comments

@dadaxr
Copy link
Contributor

dadaxr commented Jun 22, 2023

There is no doc about how to filter collection entries based on a mapped taxonomy.

There is a quick mention to the existence of two methods "whereTaxonomy" and "whereTaxonomyIn" but no examples of how to use it. IMHO, we should mention them in the https://statamic.dev/repositories/entry-repository#querying doc page, with some examples.

It took me a while to understand we should follow this format :

Entry::query()
    ->where('collection', 'blog')
    ->whereTaxonomy('tag::holidays') //here "tag" is the taxonomy id, and "holidays" the term id
    ->get();
Entry::query()
    ->where('collection', 'blog')
    ->whereTaxonomyIn(["tag::holidays","tag::news"]) // == entries having either a "holidays" tag OR a "news" tag
    ->get();

It could also be great to mention that only works if the "taxonomy id" (ie "tag" in the above example), match a field "named" tag in the collection blueprint. If it does not, the "whereJsonContains" workaround could also be documented : statamic/cms#4098 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants