We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20178
    • 82 Posts
    i can’t seem to get that to work it’s just throwing up an Internal Server Error when i call that snippet on the page.
      • 3749
      • 24,544 Posts
      Paste your full snippet code in here. Maybe we can see a problem with it.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 20178
        • 82 Posts
        thanks bobray -

        the snippet that i call on my resource is ; [[MySnippet]]

        <?php
        $zip = 'red';
        $zipUsers = array();
        /* get all active users */
        $users = $modx->getCollection('modUser',array('active' => '1'));
        foreach ($users as $user) {
            /* get the user's profile */
            $profile = $user->getOne('Profile');
            $extendedFields = $profile->get('extended');
            /* get the user's zip code */
           $userZip = $extendedFields->get('color');
            /* if the user has the zip code, add them to the array */
           if ($userZip == $zip) {
                $zipUsers[] = $user->get('username');
            }
        }
        
        foreach($zipUsers as $zipUser) {
        
            $output .= '<p>User: ' . $zipUser->get('username') . '</p>';
        
        }
        return $output;



        Have just had another test and it’s till throwin up server errors.

        thanks advance.
          • 3749
          • 24,544 Posts
          Let’s put in some quick and dirty sanity checks:

          <?php
          $zip = 'red';
          $zipUsers = array();
          /* get all active users */
          $users = $modx->getCollection('modUser',array('active' => '1'));
          
          if (! $users) {
             return "No Users Found";
          }
          foreach ($users as $user) {
              /* get the user's profile */
              $profile = $user->getOne('Profile');
              if (! $profile) {
                    return 'User ' . $user->get->('username') . ' has no profile';
              {
              $extendedFields = $profile->get('extended');
          
              if (! $extendedFields) {
                   return 'Could not get extended fields for User: ' . $user->get->('username') ;
              }
              /* get the user's zip code */
             $userZip = $extendedFields->get('color');
              /* if the user has the zip code, add them to the array */
             if ($userZip == $zip) {
                  $zipUsers[] = $user->get('username');
              }
          }
          
          foreach($zipUsers as $zipUser) {
          
              $output .= '<p>User: ' . $zipUser->get('username') . '</p>';
          
          }
          return $output;


          Remember that anonymous users in the front end have no profile.

            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting