-
Notifications
You must be signed in to change notification settings - Fork 314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: No mapping found for [popularity] in order to sort on #3535
Comments
This is fixed in #3502 (see 6834542) In the meantime, users facing this problem can drop the following snippet in a custom plugin or their theme's functions.php file: /**
* Translate WooCommerce `price` and `popularity` fields in orderby clauses.
*
* This should be removed if using versions of ElasticPress newer than 4.6.1
*
* @see https://github.com/10up/ElasticPress/issues/3535
* @param \WP_Query $query The WP Query
*/
function ep_custom_fix_woocommerce_fields_sort_translation( $query ) {
if ( ! is_plugin_active( 'elasticpress/elasticpress.php' ) || ! defined( 'EP_VERSION' ) ) {
return;
}
if ( version_compare( EP_VERSION, '4.6.1', '>' ) ) {
_deprecated_function( __METHOD__, 'EP 4.6.1', 'This function is not needed anymore.' );
return;
}
$orderby = $query->get( 'orderby', '' );
if ( ! in_array( $orderby, [ 'price', 'popularity' ], true ) ) {
return;
}
$orderby_field = ( 'price' === $orderby ) ?
'meta._price.double date' :
'meta.total_sales.double date';
$query->set( 'orderby', $orderby_field );
}
add_action( 'pre_get_posts', 'ep_custom_fix_woocommerce_fields_sort_translation' ); |
The underlying issue (why these queries are integrated) is here: public function should_integrate_with_query( \WP_Query $query ) : bool {
/**
* Check for taxonomies
*/
$supported_taxonomies = $this->get_supported_taxonomies();
$tax_query = $query->get( 'tax_query', [] );
$taxonomies_queried = array_merge(
array_column( $tax_query, 'taxonomy' ),
array_keys( $query->query_vars )
);
if ( ! empty( array_intersect( $supported_taxonomies, $taxonomies_queried ) ) ) {
return true;
} Basically, any WP_Query with a taxonomy that is supported by the WooCommerce feature will be integrated. Do we want to change that criteria? |
We will remove the automatic integration and keep it only for main queries and searches. |
Describe the bug
Under certain circumstances for WooCommerce stores, ElasticPress will integrate a WP_Query that is not the main query, causing an error
No mapping found for [popularity] in order to sort on
Steps to Reproduce
Place the following snippet anywhere:
Screenshots, screen recording, code snippet
No response
Environment information
No response
WordPress and ElasticPress information
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: