Copied to clipboard

Flag this post as spam?

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


  • Keith 12 posts 91 karma points
    Jun 21, 2024 @ 08:16
    Keith
    0

    Return content by document type

    Hi

    My site has a varied structure where where the parent 1 node contains items of different document type called X (example). Then parent 2 contains more nodes of the same document type X as parent 1 and this pattern continues.

    I'm trying to return all the items of the document X and then have the parent node listed too.

    I read I could use IContentTypeService but some suggest this is slow and to use IPublishedContent. I read up on the documentation but not really sure where to start?

    Could anyone give some starting tips?

    Thanks in advance

  • Huw Reddick 1920 posts 6648 karma points MVP 2x c-trib
    Jun 26, 2024 @ 09:42
    Huw Reddick
    1

    Hi Keith,

    This should help you get started

    var rootnode = (IPublishedContent)Umbraco.ContentAtRoot().FirstOrDefault();
    IEnumerable<IPublishedContent>
    mynodes = rootnode.Descendants().Where(x => x.ContentType.Alias.ToLower() == "{documentalias}");
    
  • AJ Murray 10 posts 99 karma points
    Jun 27, 2024 @ 05:21
    AJ  Murray
    0

    Umbraco recommend to only use IContentService if you are updating data. If just querying then use IPublishedContentQuery.

    https://docs.umbraco.com/umbraco-cms/v/13.latest-lts/reference/querying/ipublishedcontentquery

Please Sign in or register to post replies

Write your reply to:

Draft