Split filter ep_set_default_sort into another one: ep_set_sort #2343
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the Change
When using the filter
ep_set_default_sort
to change search results to sort bypost_date
instead ofscore
, it causes a malformed query on non-search results. This happens at theparse_orderby()
level:ElasticPress/includes/classes/Indexable/Post/Post.php
Line 1915 in a796de7
This is because $formatted_args['sort'] does not return a valid result since it's not expecting a nested array:
For example, I'd expect a result like:
Would it be possible to use a different hook,
ep_set_default_orderby
in the first filtering instance, as it is expecting a string input?ElasticPress/includes/classes/Indexable/Post/Post.php
Lines 866 to 874 in a796de7
...Versus in the second instance, where it's a nested array (this is where we are using it to hook for the result sorting):
ElasticPress/includes/classes/Indexable/Post/Post.php
Lines 882 to 898 in a796de7
Alternate Designs
parse_orderby()
logic could be re-factored to account for a nested array input as well, but that might introduce some confusion since the filter is being used differently in two places.Benefits
Passing in a nested array into
ep_set_default_sort
doesn't unexpectedly breakparse_orderby()
(i.e. we have a CLI that callsformat_args()
)Possible Drawbacks
Those already filtering with
ep_set_default_sort
using a string input may have to revise their code to account for the new filterVerification Process
ep_set_default_sort
to sort search results by date:Checklist:
Changelog Entry
Added: Split filter
ep_set_default_sort
into additional one,ep_set_default_orderby