diff --git a/future/includes/class-gv-template-view-table.php b/future/includes/class-gv-template-view-table.php index 1067fe24a6..89c01cb6cd 100644 --- a/future/includes/class-gv-template-view-table.php +++ b/future/includes/class-gv-template-view-table.php @@ -90,15 +90,13 @@ public static function add_columns_sort_links( $column_label, $context = null ) $class = 'gv-sort'; - $sort_field_id = \GravityView_frontend::_override_sorting_id_by_field_type( $context->field->ID, $context->view->form->ID ); - $sort_args = array( sprintf( 'sort[%s]', $context->field->ID ), 'asc', ); // If we are already sorting by the current field... - if ( ! empty( $sorting['key'] ) && (string) $sort_field_id === (string) $sorting['key'] ) { + if ( ! empty( $sorting['key'] ) && (string) $context->field->ID === (string) $sorting['key'] ) { switch ( $sorting['direction'] ) { // No sort diff --git a/future/includes/class-gv-view.php b/future/includes/class-gv-view.php index 864a1e4a5d..26cfc7edfd 100644 --- a/future/includes/class-gv-view.php +++ b/future/includes/class-gv-view.php @@ -1077,9 +1077,15 @@ public function get_entries( $request = null ) { * Apply multisort. */ if ( ! empty( $has_multisort ) ) { + // Clear ordering that was set when initializing the query since we're going to set it from scratch. + ( function () { + $this->order = []; + } )->bindTo( $query, $query )(); + $atts = $this->settings->as_atts(); $view_setting_sort_field_ids = \GV\Utils::get( $atts, 'sort_field', array() ); + $view_setting_sort_directions = \GV\Utils::get( $atts, 'sort_direction', array() ); $has_sort_query_param = ! empty( $_GET['sort'] ) && is_array( $_GET['sort'] ); @@ -1096,21 +1102,20 @@ public function get_entries( $request = null ) { $sort_directions = $view_setting_sort_directions; } - $skip_first = false; - foreach ( (array) $sort_field_ids as $key => $sort_field_id ) { + $sort_field_id = \GravityView_frontend::_override_sorting_id_by_field_type( $sort_field_id, $this->form->ID ); + $sort_direction = strtoupper( \GV\Utils::get( $sort_directions, $key, 'ASC' ) ); - if ( ! $skip_first && ! $has_sort_query_param ) { - $skip_first = true; // Skip the first one, it's already in the query + if ( empty( $sort_field_id ) ) { continue; } - $sort_field_id = \GravityView_frontend::_override_sorting_id_by_field_type( $sort_field_id, $this->form->ID ); - $sort_direction = strtoupper( \GV\Utils::get( $sort_directions, $key, 'ASC' ) ); + $sort_field_id = explode( '|', $sort_field_id ); + + foreach ( $sort_field_id as $id ) { + $order = new \GF_Query_Column( $id, $this->form->ID ); - if ( ! empty( $sort_field_id ) ) { - $order = new \GF_Query_Column( $sort_field_id, $this->form->ID ); - if ( 'id' !== $sort_field_id && \GVCommon::is_field_numeric( $this->form->ID, $sort_field_id ) ) { + if ( 'id' !== $id && \GVCommon::is_field_numeric( $this->form->ID, $id ) ) { $order = \GF_Query_Call::CAST( $order, defined( 'GF_Query::TYPE_DECIMAL' ) ? \GF_Query::TYPE_DECIMAL : \GF_Query::TYPE_SIGNED ); } diff --git a/includes/class-frontend-views.php b/includes/class-frontend-views.php index 3fd2a0d84b..b930516c87 100644 --- a/includes/class-frontend-views.php +++ b/includes/class-frontend-views.php @@ -1416,17 +1416,20 @@ public static function _override_sorting_id_by_field_type( $sort_field_id, $form * Override how to sort when sorting full name. * * @since 1.7.4 + * @since TBD Default sorting is set to first and last name. * - * @param string $name_part Sort by `first` or `last` (default: `first`) + * @param string $name_part Sort by `first`, `last` or `first-last` (default: `first-last`) * @param string $sort_field_id Field used for sorting * @param int $form_id GF Form ID */ - $name_part = apply_filters( 'gravityview/sorting/full-name', 'first', $sort_field_id, $form_id ); + $name_part = apply_filters( 'gravityview/sorting/full-name', 'first-last', $sort_field_id, $form_id ); if ( 'last' === strtolower( $name_part ) ) { $sort_field_id .= '.6'; - } else { + } elseif ( 'first' === strtolower( $name_part ) ) { $sort_field_id .= '.3'; + } elseif ( 'first-last' === strtolower( $name_part ) ) { + $sort_field_id = "{$sort_field_id}.3|{$sort_field_id}.6"; } } break; diff --git a/readme.txt b/readme.txt index b2e3eb688b..abb59d86ae 100644 --- a/readme.txt +++ b/readme.txt @@ -26,6 +26,7 @@ Beautifully display your Gravity Forms entries. Learn more on [gravitykit.com](h * Fixed: Deprecated filter notice if using GravityView Maps 3.1.0 or newer. * Fixed: PHP 8.2 deprecation notice due to passing an empty value to `htmlspecialchars()` and creating dynamic class properties. * Fixed: The maximum number of files allowed in the File Upload field was not respected when editing an entry. +* Fixed: Sorting the View by the Name field would yield incorrect results. = 2.27.1 on August 14, 2024 =