Forums Forums Search & Filter Pro How to change search results sort order

Viewing 10 posts - 1 through 10 (of 28 total)
  • Anonymous
    #270290

    Hi, thanks for this great plugin. We’re trying to sort search results alphabetically using a custom field in the post. My programmer wrote some code that sorts them that way on the archive pages, but it’s not working for the search&filter results page. How can we achieve this? Thanks for your help!

    Trevor
    #270325

    If you want to use custom code (PHP), you will need to use this filter (it accepts arguments in the same way as wp_query):

    https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments

    Anonymous
    #270369

    Thanks, but my programmer can’t quite figure out what you meant here. Here’s the code we used to sort the results and it works on other pages but not with your search results.

    add_action( ‘pre_get_posts’, ‘wpse183601_filter_category_query’ );
    function wpse183601_filter_category_query( $query ) {
    if( is_tax() && !is_admin() && $query->is_main_query() ) {
    $query->set( ‘orderby’,’meta_value’ );
    $query->set( ‘meta_key’,’last_name’ );
    $query->set( ‘order’,’ASC’ );
    }
    }

    Can you please let me know how to get the above to work on your results pages? Thank you so much for your help.

    Trevor
    #270465

    Did you try and set this sort order in the ‘Posts’ tab of the form settings?

    Anonymous
    #270542
    This reply has been marked as private.
    Trevor
    #270546

    It might be an issue with the PHP variable max_input_vars (the PHP installation default for that variable is 1000, which is rarely anywhere near enough for WordPress).

    So, that would be something I would check. The setting can be seen in WordPress admin, here:

    https://www.screencast.com/t/pDBy7oDB

    Anonymous
    #270548
    This reply has been marked as private.
    Trevor
    #270552

    This is a server setting. Most hosts have a setting that the user can change in the hosting control panel, but you would need to consult the host’s knowledgebase/documentation for guidance.

    I would try setting it to 5000.

    Anonymous
    #270605
    This reply has been marked as private.
    Trevor
    #270693
    This reply has been marked as private.
Viewing 10 posts - 1 through 10 (of 28 total)