While LiveWhale widgets come with a variety of sort methods, there are occasions when you’ll need a custom sort method to meet a specific need. To create a custom sort method for a LiveWhale widget, you’ll need SFTP access to your server and a reasonable knowledge of PHP and SQL.
Connect to your server via SFTP and locate your /livewhale/client/global.config.php in the LiveWhale back-end.
The following code adds a reverse sort for a custom profile field (ex., profiles_102).
$_LW->REGISTERED_WIDGETS['profiles']['widget']['sort_fields'] =
['Year: Latest to top' => 'profiles_102 DESC'];
You can alter the above example to sort however you’d like.
- Enter the content type (profiles, news, events, forms, galleries, etc):
$_LW->REGISTERED_WIDGETS[‘content type here’][‘widget’][‘sort_fields’]. - Enter the label of the your sort method which will be shown in your widget editor drop-down menu (ex. ‘Custom Field: Year’)
- Enter the field to sort by and the sorting method (Desc, Asc) (ie, ‘profiles_102 DESC’) is the SQL sort that will be used to order the results.
- You can list secondary (or tertiary) sorting preferences, comma separated after the first, as in a typical SQL query SORT BY (e.g., profiles_102 DESC, profiles_103 – for built-in fields, use the table name, e.g., profiles_102 DESC, livewhale_profiles.title)
Once you’ve added the statement in your configuration file visit your widget editor for the matching widget type to make sure that the sort method appears and works as you intend.
Note: To add additional sorts to multiple widget types you’ll need a separate config statement for each.