• Resolved greg52991

    (@greg52991)


    When building a query, I see I can add a sort with:
    $query->sort(“field name”);

    Is there any way to sort by “this field” then “that field”, then “another field”?

    Thanks for any help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Chester McLaughlin

    (@chetmac)

    Yes.

    
    $sort = array(
        array('field' => 'this field', 'direction' => 'asc'),
        array('field' => 'that field', 'direction' => 'desc'),
        array('field' => 'another field', 'direction' => 'asc')
    );
    
    $query->sort($sort);
    

    For reference, here is the source of the Airpress sort method:

    
    function sort($sort,$direction="asc"){
      if (!is_array($sort)){
        $sort = array(array("field" => $sort, "direction" => $direction));
      } else {
    
        if (isset($sort["field"])){
    
          if (!isset($sort["direction"])){
            $sort["direction"] = $direction;
          }
    
          $sort = array($sort);
        }
    
      }
    
      $this->parameters["sort"] = $sort;
      return $this;
    }
    
    Thread Starter greg52991

    (@greg52991)

    Ah.. perfect! Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Sort by more than one field’ is closed to new replies.