Forums › Forums › Search & Filter Pro › Edit Query Arguments Not Working
Tagged: query arguement
- This topic has 5 replies, 2 voices, and was last updated 5 years, 1 month ago by Trevor.
-
Anonymous(Private) September 26, 2019 at 3:39 pm #222024
Hello!
I’m having some trouble editing the search query. I’m using the plugin alongside Relevanssi and want results to be sorted by relevance as well as post_date or modified date. I tried adding this to the functions file
function filter_function_name( $query_args, $sfid ) { //if search form ID = 225, the do something with this query if($sfid==5671) { //modify $query_args here before returning it $query_args['orderby'] = 'post_date'; } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
But it doesn’t amend the search URL or results.
Any help would be greatly appreciated!
Trevor(Private) September 26, 2019 at 5:53 pm #222075Did you try using the Post Date sorting option in the Posts settings tab of the form?
With your code, I am not sure if one is overriding the other. I will need to ask the developer, Ross, what happens in this situation, and if it can be done.
Let me know the answer to my question, and then we will see where we need to go from there?
Anonymous(Private) September 27, 2019 at 12:34 pm #222161Thanks for your reply Trevor.
I tried that and it doesn’t affect the order of the results. If I append “&orderby=post_date&order=desc” to the search results URL it sorts the results. Is there any way add that string to a search submit on a specific search box?
Anonymous(Private) September 27, 2019 at 4:09 pm #222197I added
global $wp_query; var_dump($wp_query->query_vars);
to the search results page and it looks like it’s picking up some of it but as a string rather than array:["orderby"]=> string(8)
Is the code I’ve added to the functions file in the correct format?
$query_args['orderby'] = 'post_date';
As it’s picking up the “orderby” but not the value “post_date”. -
AuthorPosts