More in this section

Forums / Developing with Sitefinity / Need to find ContentBlocks using multiple tags

Need to find ContentBlocks using multiple tags

3 posts, 0 answered
  1. Paul
    Paul avatar
    9 posts
    Registered:
    11 Aug 2010
    22 Jun 2012
    Link to this post
    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
  2. Paul
    Paul avatar
    9 posts
    Registered:
    11 Aug 2010
    22 Jun 2012
    Link to this post
    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
  3. Brett Whittington
    Brett Whittington avatar
    89 posts
    Registered:
    10 Aug 2012
    22 Jun 2012
    Link to this post
    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.
3 posts, 0 answered