Forums Forums Search & Filter Pro default sort

Viewing 8 posts - 1 through 8 (of 8 total)
  • Anonymous
    #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
    #1470

    Hey 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
    #1480

    Hi 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.

    Anonymous
    #1481
    This reply has been marked as private.
    Ross Moderator
    #1488

    Hey 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

    Anonymous
    #1508

    Feature request added! Thanks.

    Ross Moderator
    #1512

    Thanks 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?

    Anonymous
    #1579

    You’re right, it’s a bit messy, but a useful workaround for the time being.

    I don’t know why I didn’t think of it.

    Thanks for your help Ross.

Viewing 8 posts - 1 through 8 (of 8 total)