tagssitefinitysitefinity-8

Find pages with certain tags in Sitefinity


I'm looking for a way to find all pages that contain certain tags. For documents I can do it like this:

// convert list of tags to list of Guids
var tagGuids = GetGuidsForTags(tags);
// find all items with one of these tags
return App.WorkWith().Documents()
    .Where(ni => ni.GetValue<IList<Guid>>("Tags").Any(tag => tagGuids.Contains(tag)) &&
        ni.Status == ContentLifecycleStatus.Live
    )
    .Get().DistinctBy(x => x.Id).ToList();

But when using App.WorkWith().Pages() instead, I get an errormessage saying that a PageNode does not have a custom field named "Tags".

An exception of type 'System.Exception' occurred in Telerik.Sitefinity.Model.dll but was not handled in user code

Additional information: Wrong custom field 'Tags' for type 'Telerik.Sitefinity.Pages.Model.PageNode'

Does anyone know how to get a list of pages that contain certain Tags? I am using Sitefinity 8.1.

To clarify I didn't add a custom Tags field to my Pages. And when I do, I get the field twice: tags field showing twice

So Sitefinity seems to have a Tags field by default...


Solution

  • Apparently I had a misconfigured Sitefinity. Once I removed the selfmade custom field Tags it removed the original one as well. So now I am left with only one, which is now a custom field. Once this was done, I could access the tags using the code in my original question...

    Wish I could explain it as it took me quite a while to figure this out.