Learn how to display first the Custom Post Type (CPT) entries on the Relevanssi result page with this tutorial.
One of the advantages of being an OsomCode subscriber is that you can propose tutorials. For example, a subscriber left me this suggestion after reading the tutorial about how to improve your Genesis search with Relevanssi:
Can you separate the results by CPT? That is, that for example the products appear first, then the blog posts and then the pages or the other CPTs.
Said and done. 🙂
Next you will find out how to sort the search results with Relevanssi and give priority to the CPTs you decide.
Snippet for sorting the search results by post type with Relevanssi
Add the following code at the end of functions.php or in your functionality plugin:
To see this and another 1097 code snippets of this website, login or subscribe here.
In this case you are ordering the display of the search results in the following way:
- Portfolio entries.
- Products.
- Posts.
- Pages.
To customize it, be sure to change the names of “portfolio” and “product” for your CPTs and order them as you like under the comment “// Put the results back together…”.
Conclusions
Now you know how to get a CPT’s entries prioritized in search results when you use Relevanssi.
Any questions? I read you in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉