Using the tag datatype for the first time. Have a list of news items, some tagged, some not and a list of tags. When I click on a tag I want to reload the page and only show news items of the relevant tag. I have :
var cat = Request.QueryString["cat"];
var articleList = Model.Descendants().Where(x => x.IsVisible() && x.GetPropertyValue<bool>("hideFromNav") == false).OrderByDescending(x => x.CreateDate);
I'm hoping I can add another WHERE clause to filter on the value of "cat" but completely stumped as to how to go about it. Not sure what I should be querying on to be honest. Docs and Google hasn't helped much. Even a Foreach look would be ok, but again, I don't know what criteria to search on.
Well I got it done but I'm not happy as it looks like I'm running two queries all the time and only using one. If anyone can suggest a better way I'd love to hear it. The main issue is that the articles may not have tags so I want to show them all initially.
var cat = Request.QueryString["cat"];
var TaggedArticleList = Umbraco.TagQuery.GetContentByTag(cat, "Articles");
var RawArticleList = Model.Descendants().Where(x => x.IsVisible() && x.GetPropertyValue<bool>("hideFromNav") == false).OrderByDescending(x => x.CreateDate);
List<IPublishedContent> combinedResults = new List<IPublishedContent>();
if(cat != null) {
combinedResults.AddRange(TaggedArticleList);
} else {
combinedResults.AddRange(RawArticleList);
}
Filter content by tag
Umb 7.6.4
Hi,
Using the tag datatype for the first time. Have a list of news items, some tagged, some not and a list of tags. When I click on a tag I want to reload the page and only show news items of the relevant tag. I have :
I'm hoping I can add another WHERE clause to filter on the value of "cat" but completely stumped as to how to go about it. Not sure what I should be querying on to be honest. Docs and Google hasn't helped much. Even a Foreach look would be ok, but again, I don't know what criteria to search on.
Any advice appreciated.
Well I got it done but I'm not happy as it looks like I'm running two queries all the time and only using one. If anyone can suggest a better way I'd love to hear it. The main issue is that the articles may not have tags so I want to show them all initially.
Thanks to Craig Mayers for the combinedResults code here: https://our.umbraco.org/forum/extending-umbraco-and-using-the-api/85839-using-two-tag-groups-for-one-search
is working on a reply...