Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a SharePoint 2010 publishing site collection with a Term Store that I want to use for navigation. I understand the process of get the collection of published pages and examining the managed metadata column for a specific term or terms, but is it possible to find all items tagged with a specific term without iterating through every single page? Kind of like flipping the one to many relationship of items, pages, etc. to terms around backwards so for each term there could be one or more items using it.

If this doesn't make sense I'll clarify.

share|improve this question
add comment

3 Answers

You probably want to use CrossListQueryInfo and CrossListQueryCache to do cross-list queries. In your case, to get all the pages that have a certain metadata tag.
Here's a link on how to do those cross list queries: http://bloggingabout.net/blogs/bas/archive/2009/03/27/using-the-crosslistqueryinfo-and-crosslistquerycache.aspx

Then, for your CAML Query you should do something like:

TaxonomySession session = new TaxonomySession(SPContext.Current.Site, true);
Term term = session.GetTerm(termId);
var wssId = TaxonomyField.GetWssIdsOfTerm(site, term.TermStore.Id, term.TermSet.Id, term.Id, false, 1).FirstOrDefault();

string query = String.Format(@"<Where><Eq><FieldRef Name='YourFieldName' LookupId='TRUE' /><Value Type='Lookup'>{0}</Value></Eq></Where>", wssId);


Hope it's what you're looking for. Happy coding!

share|improve this answer
add comment

Using the query hints above I was able to build some web parts the show the term store as navigation and trigger that term search:

enter image description here

It's also available for A-Z glossary (flat structure):

enter image description here

Hope that helps.

share|improve this answer
add comment

Yes, that is possible and perhaps Metadata navigation feature of list/libraries is using it behind the scene.

The article below precisely describes what it takes to build a CAML to query list/library items based on managed metadata fields:

Querying on Managed Metadata Field Values in SharePoint Server 2010 (ECM)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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