Copied to clipboard

Flag this post as spam?

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


  • Norman Lynch 5 posts 86 karma points
    Jul 27, 2015 @ 18:53
    Norman Lynch
    1

    How do I get published AND unpublished children of a page

    In a surface controller, I need to get ALL the children of a particular page. The code I've got is:

        IPublishedContent blogParentPage = Umbraco.TypedContent(blogParentPageId);
        IEnumerable<IPublishedContent> existingPosts = blogParentPage.Children;
    

    ... but this is only returning the published children. I need the unpublished children too.

    Any hints or suggestions?

    -- Norman Lynch

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Jul 27, 2015 @ 19:18
    Dirk De Grave
    100

    you have to go via the ContentService if you want unpublished nodes as well.

    Disclaimer: this is certainly NOT how you should fetch data in a view, so you better have a good reason to do that!!

    See https://our.umbraco.org/documentation/Reference/Management-v6/Services/ContentService

  • How Do I Delete My Account? 68 posts 432 karma points
    Jul 28, 2015 @ 10:56
    How Do I Delete My Account?
    0

    On another note. How do you use ContentSerice in a View? I can't get it to work...

    (I also want unpublished content) hehe :)

  • Norman Lynch 5 posts 86 karma points
    Jul 27, 2015 @ 19:58
    Norman Lynch
    0

    That worked perfectly!

            IEnumerable<IContent> existingPosts = Services.ContentService.GetChildren(blogParentPageId);
    
  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Jul 28, 2015 @ 11:01
    Dirk De Grave
    0

    this should work in a view

    UmbracoContext.Current.Application.Services.ContentService

  • 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