Try Now
More in this section

Forums / Developing with Sitefinity / Retrieving all content item types based on a tag selection

Retrieving all content item types based on a tag selection

1 posts, 0 answered
  1. Johan
    Johan avatar
    17 posts
    18 Apr 2014
    30 Apr 2014
    Link to this post

    I need to retrieve all the content item types (blog, news, event, custom ones, etc.) based on a tag: I have followed the code that Ivan suggested on this thread: http://www.sitefinity.com/developer-network/forums/sitefinity-sdk/sitefinity-4-0-taxonomy-categorization#1454545 , but I always received 0 result. I have made sure that there are some blog posts and news items that are tagged by the right tag name. Below are the code that I use, some guidance to find out why it is not returning any result is appreciated

    public ActionResult Index()
        var model = new AssociatedInsightsModel();
        var taxonomyManager = TaxonomyManager.GetManager();
        var taxon = taxonomyManager.GetTaxa<FlatTaxon>().FirstOrDefault(t => t.Title.ToUpper() == "TEST");
        string itemTypeName = "Telerik.Sitefinity.GenericContent.Model.ContentItem";
        Type itemType = TypeResolutionService.ResolveType(itemTypeName);
        var manager = ManagerBase.GetMappedManager(itemType, "");
        ContentDataProviderBase contentProvider = manager.Provider as ContentDataProviderBase;
        var items = GetItems(taxon, contentProvider, itemType);
        return View("Default", model);
    private TaxonomyPropertyDescriptor GetPropertyDescriptor(Type itemType, ITaxon taxon)
        return TaxonomyManager.GetPropertyDescriptor(itemType, taxon);
    private IEnumerable GetItems(ITaxon taxon, ContentDataProviderBase contentProvider, Type itemType)
        TaxonomyPropertyDescriptor prop = GetPropertyDescriptor(itemType, taxon);
        int? totalCount = 0;
        var items = contentProvider.GetItemsByTaxon(taxon.Id, prop.MetaField.IsSingleTaxon, prop.Name, itemType, string.Empty, string.Empty, 0, 100, ref totalCount);
        return items;


1 posts, 0 answered