Forums › Forums › Search & Filter Pro › default sort
- This topic has 7 replies, 2 voices, and was last updated 10 years, 5 months ago by Anonymous.
-
Anonymous(Private) June 11, 2014 at 11:33 am #1462
Hi Ross,
The plugin is great, and the sort function is excellent. Is it possible to have the sort dropdown set to one option by default on page load?
I can sort the data in the template but then the sort dropdown doesn’t change the order.
Thanks
Adi
Ross Moderator(Private) June 11, 2014 at 6:26 pm #1470Hey Adrian
There is not a way to do that currently… I will include this in a future update but not quite sure how long just yet.
Take a look at my note here – https://support.searchandfilter.com/forums/topic/results-showing-from-excluded-categories/#post-821
If you want to set any default behaviour for the search form then you will need to hook in to
pre_get_posts
and order the results yourself.Something like:
function order_results_default( $query ) { global $sf_form_data; if ( $sf_form_data->is_valid_form() && $query->is_main_query() ) { //order results $query->set('orderby', 'title'); $query->set('order', 'ASC'); } } add_action( 'pre_get_posts', 'order_results_default' );
You can find the different parameters available here – http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
๐
Anonymous(Private) June 12, 2014 at 11:34 am #1480Hi Ross,
Thanks for your reply.
I tried your code, but it does not change the sort order. I also tried similar code from here (I am using advanced custom fields, but your code didn’t work even sorting by title):
http://www.advancedcustomfields.com/resources/how-to/orde-posts-by-custom-fields/#pre_get_posts which also does not work.However this works:
http://www.advancedcustomfields.com/resources/how-to/orde-posts-by-custom-fields/#wp_query in the template but then the sort dropdown doesn’t change the order.This is probably outside your remit, but any further advice would be greatly appreciated.
Ross Moderator(Private) June 12, 2014 at 3:47 pm #1488Hey Adrian thanks for the headsup..
Let me have a think about the rest, there might be a workaround.
Can you add this to the feature requests section?
https://support.searchandfilter.com/forums/forum/search-filter-pro/feature-requests/
Thanks
Ross Moderator(Private) June 13, 2014 at 6:31 pm #1512Thanks Adrian I saw that..
I had one idea (but its a bit of a messy workaround to me) to get the default sort working.. ๐
Basically, submit your form with no parameters selected except the sorting that you want, then copy and paste the URL of the results (and use this for linking to the search form ๐ )
Does that work?
-
AuthorPosts