Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Morten Peter Hagh Jensen 25 posts 85 karma points
    Sep 12, 2017 @ 07:08
    Morten Peter Hagh Jensen
    0

    Getting all items containing tag in CSV list

    I am trying to get all blog items containing a tag taken from a tag querystring.

    I have this:

    var blogItems = Umbraco.TypedContent(Model.Content.Id).Children.Where(x => x.DocumentTypeAlias == "BlogItem" && x.IsVisible() && x => x.GetPropertyValue<string>("tagsList").Split(",").Contains(tags)).OrderByDescending(x => x.CreateDate);
    

    But I am getting an CS1026: ) expected error

    So basically I want to get all items where "tag" is in the "tagsList" textfield on the blogItem

  • Kevin Jump 2348 posts 14896 karma points MVP 8x c-trib
    Sep 12, 2017 @ 07:25
    Kevin Jump
    0

    Hi

    I think your query just has a few syntax issue - below should work:

    var blogItems = Umbraco.TypedContent(Model.Content.Id)
        .Children.Where(x => x.DocumentTypeAlias == "BlogItem" && x.IsVisible() && x.GetPropertyValue<string>("tagsList").Split(',').Contains(tags))
        .OrderByDescending(x => x.CreateDate);
    

    (the second x => to just x, and Split(",") becomes Split(','))

    umbraco does also have helper functions for tags such as

    Umbraco.TagQuery.GetContentByTag(tag);
    

    that might help, but i am not sure if you can do multiple tags in the same query with that.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies