• Hello. Hope are you doing well.

    Hello. I need Pages to be first in searches, then Posts.

    Now the pages are not showing up in searches at all and I don’t understand why. Let’s say there is a “How we do it” Page. And it needs to be shown first for the “how” request (I excluded how from the stop words) because it is basic, and only then Posts are shown.

    I can’t set this up in any way and haven’t found a solution in searching on your site and on the Internet.

    Is it possible to do this and if so, how?

    I searched on Google and didn’t find the right solution.
    Do you need a free or paid version?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Mikko Saari

    (@msaari)

    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.

    Thread Starter Alex Stark

    (@ut4utc)

    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.

    Plugin Author Mikko Saari

    (@msaari)

    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?

    Thread Starter Alex Stark

    (@ut4utc)

    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.

    Plugin Author Mikko Saari

    (@msaari)

    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Show Pages first in search – how?’ is closed to new replies.