Skip Navigation

[Resolved] How to overwrite toolset sort setting

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 9 replies, has 2 voices.

Last updated by Minesh 5 months, 2 weeks ago.

Assisted by: Minesh.

Author
Posts
#2748521

I got a map and after i query the location it do a ajax refresh and show the nearest center within the vicinity. I got set the ordering in my view settings
hidden link

#2748561

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please describe the issue in brief. In what order you want to display the filtered results.

Can you please share exact steps that I should follow and it should lead me to see the current issue and what is your expected result.

Could you please send me debug information that will help us to investigate your issue.
=> https://toolset.com/faq/provide-debug-information-faster-support/

#2749091
preschool_distance.png

Hi I followed this but the order still incorrect.
https://toolset.com/forums/topic/can-i-sort-a-query-view-differently-before-and-after-the-query-has-been-used/

i got a search address input such that when i search the result return will be a the post within 5km. I successfully got the post but i can't sort them by nearest distance.

#2749251

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please share details what address I should use to search and what is your expected order to display the result and send me problem URL and admin access details and let me review what could be the possible workaround or solution I may offer you, if it really possible.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2749801

I might not be able to provide access. can let me know which code you would like to review?

You can try type "522663" postal and select the suggest address

#2749946

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok - if you not able to share production site access details then you can share with me staging site access details.

Also, as shared in what sort order you want to display the result? Also I need to review your current view settings as well.

If you can share staging site access details that would be great or if you want I can give you sandbox site where you can setup same view with few entries and then I will take a look further.

Please let me know with what option you would like to proceed further.

#2751364

My current primary ordering in acf field count and secondary sorting is post title. after user enter a address it will filter out the post by nearest 5km posts. the result will be sort as nearest centre at the top.

I tried to log the id to see it exist and below is my code:
error_log('lk-test custom_combined_filter_query filtered_ids: ' . $_GET['filtered_id_by_location']);
if (!empty($_GET['filtered_id_by_location'])) {
$filtered_ids = array_map('intval', explode(',', $_GET['filtered_id_by_location']));
$query_args['post__in'] = $filtered_ids;
//error_log('Filtered IDs applied in custom_combined_filter_query: ' . var_dump($filtered_ids));
$query_args['orderby'] = implode(", ", $filtered_ids);
}

Beside the above can i also check the pagination, after i search, it successfully return the unsorted post, but when i click on page 2 the filtered post got reset.

you may try this postal: 522663 for the search and clicking on page 2 from the pagination

#2751420

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I'm not sure but you may have use the search section and result section displayed in different section of the page. If this is true - What if you try to filter the view without using ajax and same for pagination.

#2756385

How about the custom sorting by my php calculated distance? any filter I can use?

#2756403

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

You may try to use the view's filter hook "wpv_filter_query":
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

Something like as the following example:

You can add the following code to "Custom Code" section offered by Toolset:
- https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ or to the the active theme's "functions.php" file.

add_filter( 'wpv_filter_query', 'func_orderby_custom_sort_by_post_in', 10, 3 );
function func_orderby_custom_sort_by_post_in( $query_args, $view_settings,$view_id ) {
    // process if only specific view
    if (  $view_id == 99999 ) {
        
        $custom_sort_ids = array(1,2,3,4,5); 
        if(!empty($custom_sort_ids)) {
            
            if(!empty($custom_sort_ids)) {
                $query_args['post__in'] = $custom_sort_ids; 
                $query_args['orderby'] = 'post__in'; 
            }
        }
    }
    return $query_args;
}

Where:
- Replace 99999 with your original view ID
- Replace $custom_sort_ids with your desired sorting post IDs