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

bbPress: Private Groups support

…forum posts private in search. Add this code to the theme functions.php file. /** * Filter search results so that private forum posts are not displayed * to members who do not belong to the particular private group. */ add_filter( ‘relevanssi_post_ok’, ‘rlv_filter_private_forum_posts’, 11, 2 ); function rlv_filter_private_forum_posts( $post_ok, $post_id )…Private Groups is a plugin that makes bbPress forum groups private. Relevanssi, however, doesn’t understand that privacy and will show those groups in the search results. Relevanssi has means to support this, however, with the help of the relevanssi_post_ok filter. Here’s some code from Mark Wass that makes the private……$post_id, $post_type ); } //Check if current user can view the forum that the post belongs to. if ( false === private_groups_can_user_view_post_id( $forum_id ) ) { $user_can_view = false; } //Filter the search results for forum topics or replies based on the users forum permission. if ( ‘reply’ === $post_type…

How to include specific posts

Hello, I’m using WooCommerce and Relevanssi and they work great. My Site Search only searches Products, however I want to let certain posts appear in the search results. Is there a way to allow certain posts to be in the results? Yes. There are many ways to do this, and……the best way depends on how many posts you want to include and how often you need to change the posts included. I’d do this by enabling posts in the site search, but then disabling indexing for all posts except those you want to include with relevanssi_indexing_restriction. This is a…

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