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

    Ive been really struggling with this for some time. No matter what suggestions I try from searching the net I just cannot get it to work.

    So far I have tried:

    &sortdir=`ASC` &sortby=`menuindex` 


    &sortby=`menuindex` &sortdir=`ASC` 


     &sortby=`{menuindex:ASC}`


    &sortby=`{"menuindex":"DESC"}`


    But just none of them will work.

    Can anyone help me out?

    Im using ModX version 2.1.3 and version 1.6.0 of getResources

      • 4172
      • 5,888 Posts
      the first two and the last should work, the third not.
      what is your whole snippet-call?
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 37110
        • 72 Posts
        What you have to do is the following thing.


        Create a snippet "getResourcesTree" with the following code:

        <?php
        if (!function_exists('multiarray_keys')) {
        function multiarray_keys($ar) {
        foreach ($ar as $k => $v) {
        $keys[] = $k;
        if (is_array($ar[$k]))
        $keys = array_merge($keys, multiarray_keys($ar[$k]));
        }
        return $keys;
        }
        }
        $parents = (!empty($parents) || $parents === '0') ? explode(',', $parents) : array($modx->resource->get('id'));
        $depth = isset($depth) ? (integer) $depth : 10;

        $tree = $modx->getTree($parents, $depth);
        $tree = multiarray_keys($tree);
        $tree = implode(',', $tree);
        $tree = 'FIELD(modResource.id, ' . $tree . ')';
        return $tree;


        And now your getResources call

        [[!getResources?
        &parents=`19,25`
        &tpl=`myTpl`
        &sortdir=`ASC`
        &limit=`50`
        &sortby=`[[!getResourcesTree? &parents=`19,25` &depth=`100`]]
        `]]






        The reason why it is not working what you wanted is that the menuindex for each level starts with a zero. So the first results are the first resrouces of all the levels.
          • 33608
          • 27 Posts
          Quote from: wiegers at Jan 10, 2014, 05:49 AM

          Create a snippet "getResourcesTree" with the following code:

          <?php
          if (!function_exists('multiarray_keys')) {
          function multiarray_keys($ar) {
          foreach ($ar as $k =--> $v) {
          $keys[] = $k;
          if (is_array($ar[$k]))
          $keys = array_merge($keys, multiarray_keys($ar[$k]));
          }
          return $keys;
          }
          }
          $parents = (!empty($parents) || $parents === '0') ? explode(',', $parents) : array($modx->resource->get('id'));
          $depth = isset($depth) ? (integer) $depth : 10;

          $tree = $modx->getTree($parents, $depth);
          $tree = multiarray_keys($tree);
          $tree = implode(',', $tree);
          $tree = 'FIELD(modResource.id, ' . $tree . ')';
          return $tree;

          This is super fantastic! Thanks!