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

    i have a problem with AdvSearch.

    the Hook works fine without extended fields
    $main = array(
        'package' => 'modx',
        'packagePath' => '{core_path}model/',  
        'class' => 'modUser',                          
        'fields' => 'username',                       
        'withFields' => 'username'
    );
     
    
    $joined = array(
        array(
            'package' => 'modx',
            'class' => 'modUserProfile',
            'packagePath' => '{core_path}model/', 
            'fields' => 'zip, city',
            'withFields' => 'zip,city',
            'joinCriteria' => 'modUser.id = modUserProfile.internalKey'
        )
    );
    
    


    but when i try the following hook then i have no output.
    (color is an extended field)

    $main = array(
        'package' => 'modx',
        'packagePath' => '{core_path}model/',  
        'class' => 'modUser',                          // you use the modUser resource as main resource
        'fields' => 'username',                        // displayed
        'withFields' => 'username',                    // where we do the search
        'sortby' => 'modUser.username DESC'
    );
     
    
    $joined = array(
        array(
            'package' => 'modx',
            'class' => 'modUserProfile',
            'packagePath' => '{core_path}model/', 
            'fields' => 'zip, city',
            'withFields' => 'zip,city,color',
            'joinCriteria' => 'modUser.id = modUserProfile.internalKey'
        )
    );
    
    


    It's possible to get extended fields with AdvSearch?

    Thanks for any ideas!

      • 5811
      • 1,717 Posts
      Extended fields are stored as json values. So you need to get first the extended field:

      $joined = array(
          array(
              'package' => 'modx',
              'class' => 'modUserProfile',
              'packagePath' => '{core_path}model/',
              'fields' => 'zip, city',
              'withFields' => 'zip,city,extended',
              'joinCriteria' => 'modUser.id = modUserProfile.internalKey'
          )
      )
      And then decode the json value where you who like use the extended fields.

      As example, the field color is stored as : {"color":"red"}
      If you have some others fields in a container you will have something like:
      {"color":"red","others":{"size":"1,80"}}
      where "others" is the container name and size a field of this container.