Quote from Softmedia on May 29, 2023, 16:44
Hello Support,
Our client (https://3d-mon.com/shop/) use your great pluginy for few years and now he wants to modify popularity sorting to be ordered by value of meta field called "last_sixtydays_total_sales".
I have already modified the query by following snippet. Also I checked var_dump() from this modified query and it looks like it is correct but the order of products isn't changed.
add_action( 'pre_get_posts', 'modify_query_sort_by_popularity', 9999 );
function modify_query_sort_by_popularity( $query ) {
if ( ! is_admin() && $query->is_main_query() ) {
if ( $query->is_post_type_archive( 'product' ) ) {
// Check if sorting by popularity
if ( isset($_GET['orderby']) && $_GET['orderby'] == 'popularity' ) {
$query->set( 'meta_key', 'last_sixtydays_total_sales' );
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'order', 'DESC' );
}
}
}
}
I think this function is later overridden by other code from your plugin running on a higher priority.
Could you help me how to modify it to get described results?
Thank you for your time.
Best regards.
Hello Support,
Our client (https://3d-mon.com/shop/) use your great pluginy for few years and now he wants to modify popularity sorting to be ordered by value of meta field called"last_sixtydays_total_sales".
I have already modified the query by following snippet. Also I checked var_dump() from this modified query and it looks like it is correct but the order of products isn't changed.
add_action( 'pre_get_posts', 'modify_query_sort_by_popularity', 9999 );
function modify_query_sort_by_popularity( $query ) {
if ( ! is_admin() && $query->is_main_query() ) {
if ( $query->is_post_type_archive( 'product' ) ) {
// Check if sorting by popularity
if ( isset($_GET['orderby']) && $_GET['orderby'] == 'popularity' ) {
$query->set( 'meta_key', 'last_sixtydays_total_sales' );
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'order', 'DESC' );
}
}
}
}
I think this function is later overridden by other code from your plugin running on a higher priority.
Could you help me how to modify it to get described results?
Thank you for your time.
Best regards.