Sort custom search results

Permalink
Hello all, I have a site using a custom search that returns property listings. The code is below. It works great, however it's not sorting the results in any way. There are Platinum, Gold, Silver and FREE properties. I need them to sort by the "package_type" attribute in that order.
<?php
defined('C5_EXECUTE') or die("Access Denied.");
$th = Loader::helper('text');
$im = Loader::helper('image');
$nh = Loader::helper('navigation');
//echo "<pre>";
//print_r($pages);
//echo "</pre>";
//die();
if(count($pages) > 0){
    //make sure there is at least one featured page
    if($pages[0]->getAttribute('is_featured')){
    ?>    
<div class="property_list_wrapper">
    <div class="col-xs-12">

 
jero replied on at Permalink Reply
jero
So this is a page list block with a custom template?

You could add some code into your template that loops through $pages, retrieving the package_type attribute and using its value to built another sorted array to replace $pages which you then let the rest of your template output.

The alternative is to override the page list block controller and use the base method's sortBy method, passing in the package_type attribute key object. You'd probably have to alter the block interface too, so that you could select package_type as a search otherwise all page lists would do this which is probably no what you want.