PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

I can't to modify orderby of query

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

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

My plugin is a filter and it doesn't affect sorting

I think this function is later overridden by other code from your plugin running on a higher priority. - It depends on where you put this code