Forums › Forums › Search & Filter Pro › A third sort order?
Tagged: orderby, results, sort order
- This topic has 4 replies, 2 voices, and was last updated 5 years, 5 months ago by
Trevor.
-
Trevor(Private) May 6, 2020 at 7:23 am #242759
You would need to return the sort order settings in the Posts tab back to default, and instead see if you can use this filter:
https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments
This filter uses the same argument structure as wp_query.
Anonymous(Private) May 6, 2020 at 4:07 pm #242855Thank you. I restored the Posts settings to the default order and used the following code, which is not affecting the sort order:
function filter_function_name( $query_args, $sfid ) { if($sfid==23142) { $query_args["orderby"] = array( 'subject_code' => 'asc', 'course_number' => 'asc', 'start_date' => 'asc', ); } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );It works if I set just a single order like so:
function filter_function_name( $query_args, $sfid ) { if($sfid==23142) { $query_args["orderby"] = 'subject_code'; } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );Do I need to format the $query_args differently? That’s how I do it in a regular WP_Query…
Thank you!
Anonymous(Private) May 6, 2020 at 4:35 pm #242872Nevermind. I didn’t realize I had to also manually add the meta_query to get the search order to work. Here is my working code:
function filter_function_name( $query_args, $sfid ) { //if search form ID = 225, the do something with this query if($sfid==23142) { $query_args["meta_query"] = array( 'relation' => 'AND', 'subject_code' => array( 'key' => 'subject_code', 'compare' => 'EXISTS', ), 'course_number' => array( 'key' => 'course_number', 'compare' => 'EXISTS', ), 'start_date' => array( 'key' => 'start_date', 'compare' => 'EXISTS', ), ); $query_args["orderby"] = array( 'subject_code' => 'asc', 'course_number' => 'asc', 'start_date' => 'asc', ); } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );Please feel free to close this ticket. Thank you!
-
AuthorPosts