Copied to clipboard

Flag this post as spam?

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

  • MB 108 posts 397 karma points
    Dec 27, 2018 @ 11:45

    Find descendants - including unpublished?

    I have an UmbracoAuthorizedJsonController that responds to a request from a BackOffice requestHelper to fetch a list of nodes below a parent.

    Currently using code along these lines, to fetch descendants below the parent nodeID, where the DocumentTypeAlias matches a filter list

    var filter = new[] { "DocumentTypeAlias1", "DocumentTypeAlias2" };
    foreach (var node in UmbracoContext.Current.ContentCache.GetById(parentID).Descendants().Where(n => n.IsVisible() && filter.Contains(n.DocumentTypeAlias)))
        //do stuff to build & return list

    It works fine for Published content, but now I need to also find Unpublished content... and I'm at a loss at the moment.

    What should I be doing to also include unpublished nodes in my list?

  • Marcio Goularte 362 posts 1266 karma points
    Dec 27, 2018 @ 14:13
    Marcio Goularte

    Unpublished content does not appear in the cache. Only published content is created in the XML cache. You can try to use Examine.

    You need to set supportUnpublished="true" in the indexer you want or you can create a custom indexer.

    And then do the content filter with examine


    you can also use contentservice to do this search. But I recommend doing examine, avoid the database calls that contentservice does

  • MB 108 posts 397 karma points
    Dec 27, 2018 @ 23:51

    Cheers - that fixed it.

    Pretty obvious when I stopped and thought about it, that UnPublished nodes would not be in a resultset of IPublishedContent nodes.

    Changing the Descendants query to use ContentService (and the appropriate changes due to handling IContent rather than IPublishedContent nodes) got me out of trouble for the time being, but I'll take a look at how I might be able to use Examine when I get the time.

Please Sign in or register to post replies

Write your reply to: