The indexing setting is all you need. There’s no need to restrict the search to the post type if it’s the only one in the index. You only need the post_type parameter in the search query if you have multiple post types in the index and only want results from one post type.
No filter functions are necessary.
Thanks! For some reason, I’m still getting results ranked by date, newest to oldest, with no post_type parameter. Where would I start to look for the problem?
What if you add &orderby=relevance&order=desc to the search query URL? Does that fix the problem? Are the results otherwise correct?
No, still by date. Maybe this is a problem with the search results template?
It’s possible, or something that overrides the sorting later. Are the results otherwise from Relevanssi? I.e. the correct post type and so on? If the results come from Relevanssi, you can try this snippet in your theme functions.php to override the order:
add_filter( 'relevanssi_modify_wp_query', function( $query ) {
$query->set( 'orderby', array( 'relevanssi' => 'desc' ) );
return $query;
} );
If this does not work, then yeah, let’s look at what your search results template has.
Ah, hah; that worked. Thanks!
Now I will look in the search results template and see what might be overriding the results so I don’t need that filter.
It might be in the theme functions.php, or come from another plugin.