New Landing How can we help? Atelier Change Search Results Order

Viewing 4 posts - 1 through 4 (of 4 total)
  • Posted in: Atelier
  • #284089
    Ian
    Member
    Post count: 121

    Is it possible to change the order of the search results?

    Currently if I search for “nettle” I get results in the following order:
    1. Ingredients ( a custom post type )
    2. post
    3. product

    I would prefer:
    1. product
    2. Ingredients ( a custom post type )
    3. post

    Also should the headings in the search not read “Products, Ingredients, Posts” for consistency?

    -Ian

    #284233
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    Please use this custom php code at functions.php of child theme:-

    function filter_search($query) {
        if ($query->is_search) {
    	$query->set('post_type', array('product', 'Ingredients ', 'post'));
        }
        return $query;
    }
    add_filter('pre_get_posts', 'filter_search');

    Thanks
    Mohammad

    #284341
    Ian
    Member
    Post count: 121

    Mohammad,

    This code works fine for limiting the post types that are returned but does not change the order in which they are returned.

    -Ian

    #284674
    David Martin – Support
    Moderator
    Post count: 20834

    Hi Ian,

    What are you looking to order the results by?

    The only plugin I know that reliable does this is a good way is the Relevanssi search plugin. It’s a plugin that does not a developer to properly set, not really plugin and play as such. Take a look and see what you think: https://www.relevanssi.com/knowledge-base/sorting-search-results/

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

You must be logged in to reply to this topic.