Created
November 25, 2025 16:48
-
-
Save g-maclean/6b97f89c960788434e0344ede5434604 to your computer and use it in GitHub Desktop.
Property Hive - Sort by Title
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Change default order (optional) | |
| add_filter('propertyhive_default_search_results_orderby', 'change_default_order'); | |
| function change_default_order( $orderby ) | |
| { | |
| return 'title_asc'; // or return ''; if you want PropertyHive's default | |
| } | |
| // Add new sort options to dropdown | |
| add_filter( 'propertyhive_results_orderby', 'ph_add_custom_title_sorting' ); | |
| function ph_add_custom_title_sorting($options) | |
| { | |
| $options['title_asc'] = 'Title (A → Z)'; | |
| $options['title_desc'] = 'Title (Z → A)'; | |
| return $options; | |
| } | |
| // Apply sorting rules | |
| add_filter( 'propertyhive_get_search_results_ordering_args', 'ph_sort_by_title' ); | |
| function ph_sort_by_title($args) | |
| { | |
| if ( isset($_GET['orderby']) ) | |
| { | |
| switch ($_GET['orderby']) | |
| { | |
| case 'title_asc': | |
| $args['orderby'] = 'title'; | |
| $args['order'] = 'ASC'; | |
| break; | |
| case 'title_desc': | |
| $args['orderby'] = 'title'; | |
| $args['order'] = 'DESC'; | |
| break; | |
| } | |
| }else{ | |
| //default, remove to use PH default | |
| $args['orderby'] = 'title'; | |
| $args['order'] = 'ASC'; | |
| } | |
| return $args; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment