We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26503
    • 620 Posts
    Trying to make the sort option work as outlined in the docs, example 5.

    Here is what I have:

    <?php
    
    
    $main =  array( 
    	'package' => 'extdata',
    	'packagePath' => '{core_path}components/extdata/model/',
    	'class' => 'ArtistGigs',
    	'fields' => 'title,venue,description,address,city,province,country,startdate,enddate', 
    	'withFields' => 'title,venue,description,address,city,province,country,startdate,enddate', 
    	//'sortby' => 'ArtistGigs.province DESC' 
    );
    
    $joined = array();
    
    $joined[0] =  array( 
        'package' => 'extdata',
        'packagePath' => '{core_path}components/extdata/model/',
        'class' => 'ArtistAttributes',
        'fields' => 'title', 
        'withFields' => '', 
        'joinCriteria' => 'ArtistAttributes.id = ArtistGigs.artistkey' 
    );
    
    $joined[1] =  array( 
        'package' => 'extdata',
        'packagePath' => '{core_path}components/extdata/model/',
        'class' => 'ArtistsManagers',
        'fields' => '', 
        'withFields' => 'name,company', 
        'joinCriteria' => 'ArtistAttributes.id = ArtistsManagers.artistkey' 
    );
    
    
    $andConditions = array(
      'ArtistGigs.province:=' => 'province',
      'ArtistGigs.genre:=' => 'genre',
      'ArtistGigs.city:=' => 'city'
    );
    
    $sort = 'sort';
    
    $qhDeclaration = array(
    	'qhVersion' => '1.2',      
    	'main' => $main,
    	'joined' => $joined,
        	'andConditions' => $andConditions,
    	'sortby ' => $sort,
    	
    );
    
    $hook->setQueryHook($qhDeclaration);
    
    
    return true;
    


    in the form I have a select control called 'sort'

    <li class="sortby">
    	<label>Sort By</label>
    	<select name="sort">
    	  <option></option>
    		<option value='province'>Province</option>
    		<option value='genre'>Genre</option>
    		<option value='city'>City</option>
    		<option value='dateasc'>Date ASC</option>
    		<option value='datedesc'>Date DESC</option>
    		<option value='artist'>Artist Name</option>
    	</select>
    </li>
    
    



    and the snippet call, no sortby=``
    [[!AdvSearch? 
         &method=`post`
         &tpl=`gigAdvSearchResult`
         &queryHook=`AdvancedSearchGigSearch`
         &containerTpl=`gigAdvSearchResults`
         &showExtract=`1:content`
         &extractLength=`350`
         &debug=`1`
         &addJQuery=`0`
      



    no matter what I do the search always returns no results and the sortby option [as seen in the debug] is always the default 'createdon ASC' ~ well it will search by a sort field if I specify it in the snippet call, but not dynamically as I need it to & in the example.

    What am I missing here?

    -thanks
    -sean
















      *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

      Sean Kimball CLP, CLS.
      Technical Director / Sr. Developer | BigBlock Studios
      ._______________________________________________.
      Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
      27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
      phone/fax: 905-426-5525
      • 3749
      • 24,544 Posts
      $sort = $_POST['sort'] ??
        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
        • 26503
        • 620 Posts
        I tried that, you would think it would work, but no - it just got ignored ... I would up having to set the sort in the main definition instead.

        if(!empty($_POST['sort'])){
        
        	$sortarr = explode(':',$_POST['sort']);
        	
        	$mysortby = $sortarr[0].'.'.$sortarr[1].' '.$sortarr[2];
        
        }else{
        	
        	$mysortby = 'ArtistGigs.province DESC';
        	
        }
        //$mysortby = $_POST['sort'];// ? $mysortby = 'ArtistGigs.province DESC' : $myortby = '';
        
        
        $main =  array( 
        	'package' => 'extdata',
        	'packagePath' => '{core_path}components/extdata/model/',
        	'class' => 'ArtistGigs',
        	'fields' => 'title,venue,description,address,city,province,country,startdate,enddate', 
        	'withFields' => 'title,venue,description,address,city,province,country,startdate,enddate', 
        	'sortby' => $mysortby, 
        );
        
          *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

          Sean Kimball CLP, CLS.
          Technical Director / Sr. Developer | BigBlock Studios
          ._______________________________________________.
          Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
          27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
          phone/fax: 905-426-5525
          • 3749
          • 24,544 Posts
          I suspect that it's the space in your $_POST variable getting encoded in the $_POST. It might work if you used urlencode() and urldecode() or separated it into separate $_POST variables: sort and sortDir.



          ------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using.
          MODX info for everyone: http://bobsguides.com/modx.html
            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