Copied to clipboard

Flag this post as spam?

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


  • Rabea_M 26 posts 140 karma points
    Jul 23, 2019 @ 07:39
    Rabea_M
    0

    Get all children of a node at Controller level either published on unpublished

    Currently i am using this method to get children of a node but it only returns the published or visible children, is there a method to get both the published and unpublished ones Current code:

    var allCount = Umbraco.Content(Guid.Parse("guidsample")).Children.ToList();
    
  • Marc Goodson 2123 posts 14214 karma points MVP 8x c-trib
    Jul 27, 2019 @ 08:52
    Marc Goodson
    101

    Hi Rabea

    Umbraco has a Published Content cache that is super optimised for reading content on the front end of your website, as its name suggests it ONLY contains 'published' items!

    The method you are using above is wired to work with the Published Content cache, which is why your unpublished items are missing.

    So in terms of what to do... depends on what you are trying to do?

    Essentially if you are working on the front end implementation of the site, then you probably shouldn't be trying to display or count unpublished items - if you need to show unpublished items on the front end efficiently in this way then publish them!! (you could add an embargo date or a checkbox to prevent content from being accessed... if that is the reason to have them unpublished but counted!)

    Now if you are in the backoffice of Umbraco, in a custom editor or event, then you can use the ContentService...

    https://our.umbraco.com/apidocs/v8/csharp/api/Umbraco.Core.Services.Implement.ContentService.html

    this operates directly against the database layer, and so is slow, and should be avoided for the front end implementation, but you'll find a GetPagedChildren + CountChildren method that may be of use.

    Finally if you are on the front end of the site, and need to query unpublished content - the other approach would be to use Examine, the search service that ships with Umbraco - the InternalIndex (usually used for the backoffice search) will contain both Unpublished and Published items, so in theory you could query this index to have a quicker way than the contentservice to locate unpublished item...https://our.umbraco.com/Documentation/Reference/Searching/Examine/

    if that helps!

    regards

    Marc

  • Rabea_M 26 posts 140 karma points
    Jul 29, 2019 @ 10:46
    Rabea_M
    0

    Thanks a lot Marc!

Please Sign in or register to post replies

Write your reply to:

Draft