• Resolved DebT

    (@debbiet)


    By default WP sorts newest Posts at the top of search results.

    I’m using WP Posts as a Members list for a sewing referral group. The search results need to be in order of seniority, so the oldest posts need to appear at the top of the search results—the opposite of the default sort order.

    In Settings/Relevanssi/Searching I see this, which looks like what I need, but there is no link for “Help” :

    “If you want to override this or use multi-layered ordering (eg. first order by relevance, but sort ties by post title), you can use the orderby query variable. See Help for more information.”

    Can you please help me? I also have a Custom Field for member number, so I could easily use that instead of date for search result order.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mikko Saari

    (@msaari)

    This should do the trick, add this to your theme functions.php:

    add_filter( 'relevanssi_modify_wp_query', 'rlv_oldest_first' );
    function rlv_oldest_first( $query ) {
        $query->set( 'orderby', array( 'post_date' => 'asc' ) );
        return $query;
    }
    Thread Starter DebT

    (@debbiet)

    Hi Mikko, thanks but for some reason that didn’t change anything.

    Also, I see that when I added your plugin, when searching on a Name (in reality, the post title) the post content loses a lot of paragraph tags.

    Such as clicking on a tag (Location) returns https://tejadadesign.com/tag/s/

    But searching on the name Nancy (Post Title) returns https://tejadadesign.com/?s=nancy

    If I deactivate Relevanssi, the results are formatted correctly on a Name search.

    Thread Starter DebT

    (@debbiet)

    Update: I found another plugin, Post Types Order, that does exactly what I needed. Thanks for your time! I’ve disabled Relevanssi, which fixed the missing paragraph tags issue when searching by name. All is well, marking this solved.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Change default search results order’ is closed to new replies.