Copied to clipboard

Flag this post as spam?

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


  • Amir Khan 1282 posts 2739 karma points
    Apr 24, 2013 @ 18:16
    Amir Khan
    0

    Get all Documents under Content not just parent node

    How do I get all document types under the content node not just the top most node under content? Like AncestorOrSelf but up one level?


    Here's whats returning everything under the top leve node I'm under, but not its siblings:

    var root = Model.AncestorOrSelf();

    // Get all descendants, filter by type:
    var nodes = root.Descendants().Where("NodeTypeAlias == @0 || NodeTypeAlias == @1", "BlogPostMC", "BlogPostHCR");
  • Douglas Ludlow 210 posts 366 karma points
    Apr 24, 2013 @ 18:30
    Douglas Ludlow
    0

    Model.AncestorOrSelf() returns the site root. To get the the true root, do the following:

    var root = Library.NodeById(-1);
    var nodes = root.Descendants();

    FYI, getting the descendants of the entire site and then filtering them is a very expensive operation. We had a lot of sites running code like this and after a little while refactored the code so it didn't and it improved load time by 400%, so beware. You may want to look a different options for querying the info you need.

  • Amir Khan 1282 posts 2739 karma points
    Apr 24, 2013 @ 18:50
    Amir Khan
    0

    Thanks Douglas, any suggestions for a good alternative? I need to pull blogs abstracts from a multisite install to the main site...

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Apr 24, 2013 @ 19:13
    Hendy Racher
    1

    Hi Amir, 

    How about: uQuery.GetNodesByType("blogPostDocTypeAlias") ? (internally that uses XPath so is quick, and will return all blogposts wherever they are in the tree).

    HTH,

    Hendy

Please Sign in or register to post replies

Write your reply to:

Draft