Question

I've got a content type with a TaxonomyField, and a number of content items with various terms associated to them. Given a term (not a term ID, but the actual textual term), what's the most efficient way to query for all content items associated with that term?

Was it helpful?

Solution

You would need to get the Term first, using the Slug (I assume that is what you mean by Term Text). Use the taxonomy service for this.

And then you can use this query

_orchardServices.ContentManager
                        .Query("CONTENT TYPE")
                        .Join<TermsPartRecord>()
                        .Where<TermsPartRecord>(x => x.Terms.Any(y => y.TermRecord.Id == RECOVERED TERM.Id)
                        .List()

You can also use WithQueryHints(new QueryHints().ExpandParts()), if you know which parts of your content items you would need (this will eagerly load them).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top