Something like this?
add_filter( 'relevanssi_modify_wp_query', function( $query ) {
$query->set( 'orderby', array( 'relevance' => 'desc', 'post_date' => 'desc' ) );
return $query;
} );
This won’t have any noticeable effect compared to just sorting by relevance. This will sort the posts by relevance, and if there’s a tie in relevance (which is rare), those tied posts are then sorted by date.
What exactly do you mean with “I want the latest posts to show up first after the most relevant ones.”? Can you give me a more concrete example of how this would work, like a list of posts with dates and made-up relevance scores, and how they should be sorted?
That’s exactly what I want, @msaari, but somehow — maybe for the same reason as the code for RSS feeds in the other topic — it’s not working for me.
What I mean is like this example here: https://d.pr/i/7GY73C
It first sorts by relevance (great), but the latest posts — probably with the same lower relevance — are shown from the oldest to the newest. I want to invert that.
Are you looking at this in the WP admin search the screenshot is from? Relevanssi does not reliably work in the admin search; for hierarchical post types, the search just does not use Relevanssi.
Are the results the same in the Relevanssi admin search (Dashboard > Admin search)?
Yes, that’s a search from the WP admin.
The results are the same from Relevanssi admin search, but the order is a bit different.
Is the order in the Relevanssi admin search correct? Is the date sorting right there? If you change the sorting completely in the function (e.g. set orderby to post_date), does that change take effect?
Really sorry for the trouble here too, @msaari. I finally caught the problem: it was a setting I previously changed in my server’s OPcache that forced a really strong cache over PHP files. Fixed that and now it’s working great!