change order of search results to show featured first

This topic contains 12 replies, has 5 voices, and was last updated by  Stiofan O’Connor 6 years, 3 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #412563

    Joshua Dobbs
    Expired Member
    Post count: 90

    I see in this thread that Stiofan was going to make changes so everything can be filtered. Is there a hook or some other way to modify the orderby clause so that featured items are first?

    #412674

    Paolo
    Site Admin
    Post count: 31206

    Hi,

    Stiofan has been alerted of your question, he’ll reply after the week end.

    Thanks

    #412682

    Dirk
    Full Member
    Post count: 390

    Hi Joshua,

    there is a filter called

    geodir_posts_order_by_sort

    that you can use, I think, also for search.
    Example is here

    Best,
    Dirk

    #412689

    Guust
    Moderator
    Post count: 29970

    Hi Dirk and Joshua, the code at https://wpgeodirectory.com/docs/common-code-snippets/#sort will not work on a search page for now unless no search terms are used by the visitor.

    Thanks

    #412718

    Dirk
    Full Member
    Post count: 390

    Hi Guust,

    I’m wondering a little bit, because I’m using

    geodir_filter_widget_listings_orderby

    filter to get listings with featured image to the front of the listings page.
    I made a quick check and for me this is working to use the mentioned filter. It is adding featured hard to the front of the orderby statement:

    
    
    add_filter('geodir_posts_order_by_sort','_my_custom_order_by',10,3);
    function _my_custom_order_by($orderby, $sort_by, $table){
    	if (is_search())
    	{
    		$orderby = $table . ".is_featured asc," . $orderby; 
    	}
    	return $orderby;
    }

    Best,
    Dirk

    #412719

    Guust
    Moderator
    Post count: 29970

    Hi Dirk, on the Search Results page? If someone searches for a keyword?

    #412720

    Dirk
    Full Member
    Post count: 390

    Hi Guust,

    for my directory I’m not using such kind of function as the search relevance is important for me. Was just curious if this is technically possible. It is just changing the order and not hiding any search result.

    But I can think of use cases that have the featured listings always in front of the search and not as second priority of the sorting. This should be the decision of the user 🙂

    Best,
    Dirk

    #412721

    Guust
    Moderator
    Post count: 29970

    Joshua wants filtering on the search page I think.

    #412722

    Dirk
    Full Member
    Post count: 390

    😉 The use case is not clear. Maybe he will answer.

    #412758

    Stiofan O’Connor
    Site Admin
    Post count: 22956
    #413068

    Joshua Dobbs
    Expired Member
    Post count: 90

    Awesome! Thanks Stiofan!!!

    #413170

    Joshua Dobbs
    Expired Member
    Post count: 90
    This reply has been marked as private.
    #413176

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Searching a post code or street will order listings by proximity to that location, as u can see in the distances.

    Thanks,

    Stiofan

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

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket