We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34072
    • 31 Posts
    Hi all,

    I’ve got a problem with using the FirstChildRedirect snippet in ModX Revolution. It’s redirecting to the last child item instead of the first. My resource set-up is like so:

    ->Parent Resource
    ->Child 1
    ->Child 2
    ->Child 3
    ->Weblink 3a
    ->Weblink 3b

    and when the user clicks on "Parent Resource" instead of being redirected to "Child 1" they are being redirected to "Child 3".

    The snippet call I’m using is
    [[!FirstChildRedirect]]


    Can anyone shed some light on this?

    Thanks!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      $children= $modx->getActiveChildren($docid, 'menuindex', 'ASC');

      It uses menuindex to determine the first child, so the resource with the lowest menuindex would be the "first" child.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 34072
        • 31 Posts
        Thanks sottwell,

        I’ve mucked around with the menu indexes and discovered that FirstChildRedirect is definitely redirecting to the resource with the highest menuindex for some reason. I’ve modified the snippet call to
        [[!FirstChildRedirect? &sortDir=`ASC`]]

        and it’s working as it should now.

        I installed FirstChildRedirect through the package management system only a couple of days ago, and haven’t modified the snippet code at all (not php savvy in the least), so any idea why it’s defaulting to the highest rather than the lowest?
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Ah, I posted the code from the Evo version. The Revo version may be doing something else altogether.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 26681 MODX Staff
            • 123 Posts
            Thanks for posting this. I had the same problem. Was driving me a bit insane until I read this - the revised snippet call definitely works though. YAY for MODx and its vibrant community forum tongue
              [sepiariver.com] (https://sepiariver.com/)
              • 36592
              • 970 Posts
              I downloaded FirstChildRedirect snippet (Version 2.2-pl) and checked the code.
              It looks like &sortDir parameter is set to "DESC" in its default property settings.
              So you can override the default value by specifying &sortDir=`ASC` in the snippet call.
              Thinking of the name of this snippet, the default value should be "ASC"...
                • 26422
                • 107 Posts
                Thanks for posting this, it was driving me nuts.
                  Crawford Paul

                  Bridgecourt Web Design - Proudly using ModX CMS
                  Serving Welland, Niagara, Ontario, Canada and the world!
                  http://www.bridgecourt.com
                  • 2954
                  • 40 Posts
                  The reason this was happening is that in the Property Set sortDir was set to the default of DESC.

                  So the code says the default is ASC, but the Property Set says DESC - the property set takes precedence.

                  You can find the Property Set for this Snippet in the "Properties" tab of the snippet.
                    • 8109
                    • 128 Posts
                    This bug persists. I can’t find a place to report the bug. Shall we rename this LastChildRedirect?
                      Revo 2.0.8-pl