1. Docs
  2. Developer Guide
  3. Miscellaneous and Snippets
  4. Changing the default sort order of properties

Changing the default sort order of properties

To change the default sort order of properties shown in search results you can add the following to your theme’s functions.php file:

add_filter('propertyhive_default_search_results_orderby', 'change_default_order');
function change_default_order( $orderby )
{
    if (
        ( isset($_REQUEST['department']) && $_REQUEST['department'] != 'commercial' ) ||
        ( !isset($_REQUEST['department']) && get_option( 'propertyhive_primary_department' ) != 'commercial' )
    )
    {
        return 'price-asc';
    }
    else
    {
        return $orderby;
    }
}}
Was this article helpful to you? Yes No