Forums Forums Search & Filter Pro order the search results

Viewing 4 posts - 1 through 4 (of 4 total)
  • Anonymous
    #2323

    Hello Ross,

    I notice the results display by date. Is there a way to choose by title, for example ?

    Best regards,

    D.

    Ross Moderator
    #2333

    Hey David, again there are no default options, so you would need to hook in to pre_get_posts to do this, I think there is another post on here where I gave some sample code to a user… I will try to find it..

    If you would like your users to be able to choose the order they see the results, then just choose the field “sort order” and add it to your form!

    Thanks

    Ross Moderator
    #2500

    Hey David

    Here is some code to hook in to the main loop for Search & Filter –

    function order_results_default( $query )
    {
        global $sf_form_data;
    	
        if ( $sf_form_data->is_valid_form() && $query->is_main_query() && !is_admin())
        {
            //order results
            $query->set('orderby', 'title');
            $query->set('order', 'DESC');
        }
    }
    add_action( 'pre_get_posts', 'order_results_default', 21 );

    This should order by title, to see other options you could look here 🙂 :
    http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

    Thanks

    Anonymous
    #2556

    Thank you Ross !

    Resolved !

    Regards

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