Relevanssi doesn’t ship with a live search feature that would display results as the user types the search terms. There are many other plugins that provide this functionality, but few work with Relevanssi. SearchWP Live Ajax Search is the best one that does. It’s very easy to use, most of the time just install and go (it doesn’t even have a settings page!).
Attachments
Sometimes the default settings are not good enough, though. One example is searching for attachments. By default, SearchWP Live Ajax Search doesn’t include any attachments in the search results. The post type is not a problem, but the post status is: SearchWP Live Ajax Search includes only posts with the post status publish
, while attachments have a status of inherit
.
This is easy to fix. Just add the following functions to your theme functions.php
file:
add_filter( 'searchwp_live_search_query_args', 'fix_searchwp_query_args' ); function fix_searchwp_query_args( $args ) { $args['post_status'] = 'inherit,publish'; return $args; }
This will set the post_status
parameter to include posts with inherit
, allowing attachments. You can also add private
to the list to include private posts for the users who are allowed to see them.
Just removing the post_status
parameter will include drafts in the results. Normally drafts shouldn’t appear in searches, but since the SearchWP Live Ajax Search is an AJAX search, it is done in admin context, where drafts are allowed.
Users and taxonomy terms
In order to see users and taxonomy terms in the search results, you also need to adjust the post_type
parameter so that either users are included or nothing is excluded. In most cases you can just remove the post_type
parameter completely and leave the post type handling to Relevanssi:
add_filter( 'searchwp_live_search_query_args', 'fix_searchwp_query_args' ); function fix_searchwp_query_args( $args ) { unset( $args['post_status'] ); unset( $args['post_type'] ); return $args; }
Users and taxonomy terms need you to blank out the post_status
parameter, which includes drafts in the results. There’s also another problem: the default template in SearchWP Live Ajax includes the name of the post type. For users, that’s not going to work, and will show empty parentheses and cause an error message in the console.
Both of these problems can be fixed with a new template. Take this template and save it as searchwp-live-ajax-search/search-results.php
under your theme. This will fix the post type name and will skip the drafts in the results.
Is it possible to open the SearchWP Live Ajax Search results in a new page? I mean when actually clicking on a live search result link to open in a new window.
George, that is something you need to ask from the SearchWP Live Ajax Search support; I don’t know.
Does SearchWP Live Ajax Search work with free version of Relevanssi?
Alan, yes, it does.
Hi Mikko!
How would I get the links added with the old school WP “links manager” included into the search.
Cheers!
/John
John, you wouldn’t; they’re not posts, and cannot be included.
Aww shucks.. thanks for the reply anyway. I guess I should have checked the restrictions before starting to add the links.