We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36656
    • 21 Posts
    I'm working on a snippet that needs to get the level of the page it's called on. I'm trying to accomplish this through getParentIds but it's returning an empty array.

    Here is what I'm using:
    $resourceId = $modx->resource->get('id');
    $levelcount = count($modx->getParentIds($resourceId));

    This is in Modx Revo. I checked the error log and didn't see anything that seemed to pertain to this problem. What should I do to try to fix this?

    Thanks in advance!
      • 22303 MODX Staff
      • 10,725 Posts
      I created a simple test snippet to check this and I am getting the proper parent id's back:

      <?php
      return implode(",", $modx->getParentIds($id));


      Calling this with an id of 48 in my site returns the three parents...
      [[!getParentIds? &id=`48`]]


      37,4,0


      Might share your version of MODX and anything else that might be relevant to you not getting the parent ids you are expecting.
        • 36656
        • 21 Posts
        Sure, here's some additional info. I tried the test snippet you provided and still no luck.

        Server:

        PHP Version: 5.2.17
        Apache: 1.3

        Modx

        Version: Revolution 2.1.2-pl
        Changes: No changes made
        Snippets: Wayfinder
        Plugins: None
          • 22303 MODX Staff
          • 10,725 Posts
          Where are you calling the Snippet? In the Template? Or is this in a tpl for Wayfinder?
            • 36656
            • 21 Posts
            The snippet is being called in a template. Depending on how deep the page is in the site the snippet will construct a Wayfinder call on the fly using various tpl chunks, start ids, etc....