Function Reference: geodir_prepare_custom_sorting
Summary
Make custom field order by clause for custom sorting.
Package
GeoDirectory
Parameters
- $sorting
- (string) (required) Listing sort option.
- Default: None
- $table
- (string) (required) Listing table name.
- Default: None
Return Values
- (string|null)
- If field exists in table returns order by clause else returns empty.
Change Log
Since: 1.6.18
Source File
geodir_prepare_custom_sorting() is located in geodirectory-functions/listing_filters.php [Line: 1049]
Source Code
function geodir_prepare_custom_sorting( $sorting, $table ) { $orderby = ''; if ( empty( $sorting ) || empty( $table ) ) { return $orderby; } if ( strpos( strtoupper( $sorting ), '_ASC' ) !== false || strpos( strtoupper( $sorting ), '_DESC') !== false ) { $sorting_array = explode( '_', $sorting ); if ( ( $count = count( $sorting_array ) ) > 1 ) { $order = !empty( $sorting_array[$count - 1] ) ? strtoupper( $sorting_array[$count - 1] ) : ''; array_pop( $sorting_array ); if ( !empty( $sorting_array ) && ( $order == 'ASC' || $order == 'DESC' ) ) { $sort_by = implode( '_', $sorting_array ); if ( geodir_column_exist( $table, $sort_by ) ) { $orderby = $table . "." . $sort_by . " " . $order; } } } } return $orderby; }