Skip to main contentSkip to footer

I’m building a directory and would like the oldest posts to automatically display first in the search results, is this possible?

I found out how to add a link that the user can click to sort the results but would like an automatic solution. Can you provide code that can be added to the functions.php or search.php file to accomplish this?

You can easily change the order to using post date from the Relevanssi settings, but that sort is newest first.

Here’s a simple function that will change the order to post date, oldest first. Just add this code to your site:

add_filter( 'relevanssi_modify_wp_query', 'rlv_asc_date' );
function rlv_asc_date( $query ) {
    $query->set( 'orderby', 'post_date' );
    $query->set( 'order', 'ASC' );
    return $query;
}

(The question was asked here.)

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Envira Gallery
Envira Gallery is a gallery plugin for WordPress. Since it uses a custom post type for the galleries, it works…

Related Posts:

Comment Section:

3 Comments. Leave new

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed