Skip to content

Commit

Permalink
Fixes query arg orderby meta_value
Browse files Browse the repository at this point in the history
  • Loading branch information
Timi-Artturi Mäkelä committed Apr 27, 2023
1 parent 372143a commit f28d6a2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [2.0.6] - 2023-04-27

### Fixed
- Fixes query argument `'orderby' => 'meta_value'`.

## [2.0.4] - 2023-02-08

### Changed
Expand All @@ -22,7 +27,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [2.0.1] - 2023-01-20

### Changed
- PHP 8.1 fixes for usort funcitons
- PHP 8.1 fixes for usort functions.

## [2.0.0] - 2023-01-13

Expand Down
2 changes: 1 addition & 1 deletion plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: RediPress
* Plugin URI: https://github.com/devgeniem/redipress
* Description: A WordPress plugin that provides a blazing fast search engine and WP Query performance enhancements.
* Version: 2.0.5
* Version: 2.0.6
* Author: Geniem
* Author URI: http://www.geniem.fi/
* License: GPL3
Expand Down
21 changes: 13 additions & 8 deletions src/Search/PostQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -925,9 +925,13 @@ protected function get_orderby() : bool {

// Create the mappings for orderby parameter
switch ( $clause['orderby'] ) {
case 'menu_order':
case 'meta_value':
case 'meta_value_num':
if ( ! empty( $query['meta_key'] ) ) {
$clause['orderby'] = $query['meta_key'];
}
break;
case 'menu_order':
break;
case 'none':
case 'relevance':
Expand Down Expand Up @@ -960,21 +964,22 @@ protected function get_orderby() : bool {
else {
return false;
}
}
}

// If we don't have the field in the schema, it's a no-go as well.
$fields = array_column( $this->index_info['attributes'], 1 );

if ( ! in_array( $clause['orderby'], $fields, true ) ) {
return false;
}
if ( ! in_array( $clause['orderby'], $fields, true ) ) {
return false;
}

return $clause;
}, $sortby
);
return $clause;

}, $sortby );

// If we have a false value in the sortby array, just bail away.
foreach ( $sortby as $clause ) {

if ( ! $clause ) {
return false;
}
Expand Down

0 comments on commit f28d6a2

Please sign in to comment.