Copied to clipboard

Flag this post as spam?

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


  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Oct 31, 2016 @ 15:42
    Michaël Vanbrabandt
    0

    Query nodes and filter on multi content node picker

    Hi all,

    what is the best way to query a content nodes list based on an id in the multi node content picker?

    var root = Umbraco.TypedContentAtRoot().First();
    var companyRepo = root.Children(c => c.DocumentTypeAlias == "companyRepo").First();
    

    So here I have my Company Repo which is a container that contains all companies. Now each company has a property called Categories which is the multi node content picker.

    I need to filter these companies based on the currentpage id that needs to be located in the Categories property.

    /Michaël

  • Alex Skrypnyk 6182 posts 24283 karma points MVP 8x admin c-trib
    Oct 31, 2016 @ 16:24
    Alex Skrypnyk
    1

    Hi Michaël,

    I would do it with this code:

    var companies = companyRepo.Children.Where(c => c.GetPropertyValue<string>("categories").IndexOf(Umbraco.AssignedContentItem.Id.ToString(), StringComparison.Ordinal) > -1);
    

    Hope it will help you.

    Thanks,

    Alex

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Nov 01, 2016 @ 10:38
    Michaël Vanbrabandt
    101

    Hi Alex,

    thanks for taking me into the right direction. I got it working by using the following code:

    var companies = companyRepo.Children
        .Where(
            c => c.GetPropertyValue<string>("categories").Split(',').IndexOf(Umbraco.AssignedContentItem.Id.ToString()
        ) > -1);
    

    /Michaël

  • Alex Skrypnyk 6182 posts 24283 karma points MVP 8x admin c-trib
    Nov 01, 2016 @ 10:39
    Alex Skrypnyk
    1

    Hi Michaël

    Glad to hear, have a nice day!

    Thanks,

    Alex

  • 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