You have two problems here. The first you need to solve is to get the pages to show up in the first place.
I assume you’ve set Relevanssi to index both posts and pages? If not, do that in the Relevanssi indexing settings and rebuild the index.
If you have set Relevanssi to index pages and searching with the Relevanssi admin search (Dashboard > Admin search) shows you pages, the problem is likely in your theme: it’s probably restricting the search results to posts only. See if you can fix that from your theme settings. If not, you can override it with this snippet:
add_filter( 'relevanssi_modify_wp_query', function( $query ) {
$query->set( 'post_types', 'post,page' );
return $query;
} );
Add this to your theme functions.php or in a code snippet. Now you should have both posts and pages in the results. Do you?
Finally, here’s how your sort pages before posts.
Thanks for trying to help. I hope you are fine.
Unfortunately, this code works, but I need to somehow influence the order in which the information is displayed.
For example, I have many pages. And many have ML in their name. But I would like to sort them somehow – let’s say the main page is ML and the sub-main ones are ML and development, ML and research…. I would like the main page to come first in the search and the rest later. How can this be done?
Thank you again for your help, have a nice day.
Do these pages have a hierarchical relationship between them, i.e. is the main page a parent of the sub-pages? If so, it would be fairly easy to do a function that guarantees the parent page appears in the results before its children. Is it just this ML and ML sub-pages group, or are there other similar groupings?
There are no hierarchical relationships. In essence, this is a flat structure, and in the hierarchy we ourselves highlight them by organizing them in the Menu, but there is no direct subordination and nesting between pages.
It’s possible to set up the way you want to, as Relevanssi gives you full control over the order of the results. You just need a clear definition of which page must go before which. The ordering itself is simple array manipulation and the tool for that is the relevanssi_hits_filter filter hook.