We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38142
    • 91 Posts
    Can I ask a really, really dumb question? How do you count the number of resources returned by getResources? I am calling getResources from within my DIY snippet like so and trying to count the number of resources returned:

        $tvfilter = 'region=='.$region.',sleeps=='.$sleeps;           
        $output = $modx->runSnippet('getResources',array(
       'parents' => '22',
       'tpl' => 'villalist',
       'limit' => '20',
        'depth' => '1',
       'showHidden' => 0,
       'includeContent' => 0,
       'includeTVs' => 1,
       'processTVs' => 1,
       'tvPrefix' => '',
       'sortBy' => RAND(),
        'tvFilters' => $tvfilter
    ));
            $resultsquantity = count($output);


    Regardless of the actual number of resources returned the count function always returns 1.

    There must be a really simple way to do this. Can't see anything in the getResources documentation, though.
      • 22303 MODX Staff
      • 10,725 Posts
      Try this after calling runSnippet()...
      $resultsquantity = (integer) $modx->getPlaceholder('total');


      You can also pass a totalVar property to getResources to override the name of the placeholder it uses to set the total. It is 'total' by default.
        • 38142
        • 91 Posts
        Thank you VERY much. That works a treat. Perhaps one day I'll figure out how it works.