I am using WordPress search to search a range of custom post types and allow the user to drill-down into each individual post type.
However I’m finding that WordPress is not returning what I’d deem to be the ‘best’ matches first. For example, if I search for Microsoft, pages that contain the term irregularly are still returned before pages that regularly use the term.
Basically I’m trying to find some information on how WordPress ranks pages and determines relevance and if I can influence this without having to install any plugins.
Any help much appreciated.
EDIT – The current version of WordPress supports relevance, so this answer is no longer accurate.
There’s no concept of rank or relevance, it’s just a simple LIKE query on the post title and content:
You can use the
posts_search
filter to modify or completely replace the search query with your own. From/wp-includes/query.php
:Also see the available query filters on the
WP_Query
Codex page.Since WordPress 3.7 (October 2013), search results are sorted by the following criteria (see ticket 7394):
Each section and any remaining posts are then sorted by date.
There are also new filters:
wp_search_stopwords
, to filter stop words ignored inWHERE
.posts_search_orderby
, to filter theORDER BY
when ordering search results.