Need to find ContentBlocks using multiple tags

Posted by Community Admin on 04-Aug-2018 13:24

Need to find ContentBlocks using multiple tags

All Replies

Posted by Community Admin on 22-Jun-2012 00:00

Hi,

I have a list of tick boxes on a form that are used to search ContentBlocks (the tick boxes are synonymous with the tags). If 3 tick boxes are checked, I want to retrieve all ContentBlock Titles that have at least one of those tick boxes (i.e. it is an OR condition). I have retrieved the GUID for each of the tags from the TaxonomyManager however I am now having trouble creating a valid expression that will select my ContentBlocks using 1 or more GUID values.

Help greatly appreciated...

Thanks

Posted by Community Admin on 22-Jun-2012 00:00

This is the current code I have added...

ContentManager mgr = ContentManager.GetManager();

List<
ContentItem> articles = new List<ContentItem>();
articles = mgr.GetContent().Where(cI => (cI.Content.Contains(expression) &&

    cI.Status == ContentLifecycleStatus.Live)).ToList();

expression is derived from a string of the format:
"(Tag.Contains(guid) OR (Tag.Contains(guid) OR (Tag.Contains(guid))" etc.

Articles does not return any values, however there are many Content Blocks tagged with those Guid's. I've got a feeling I'm searching the actual content here rather than the tag, can anyone point me in the right direction?

Cheers

Posted by Community Admin on 22-Jun-2012 00:00

As you have hinted at, it appears you are just searching for your tags in the content of your Content Blocks.  I had to do something similar and I used the following post to help me out. 
http://www.sitefinity.com/devnet/forums/sitefinity/sdk/sitefinity-4-0-taxonomy-categorization.aspx

I've used this solution to grab all the items that had one category.  You might have to call this 3 times to get all the items you want and then you might have to filter out the duplicates.  Or you might be able to figure out have to combine all the calls.   Hopefully this helps.  I apologize as I don't have any specific code to give you.

This thread is closed