Skip to main contentSkip to footer

If you want to have sticky posts first in results when they match the search query, just add this code to your theme functions.php:

add_filter( 'relevanssi_hits_filter', 'rlv_sticky_first' );
function rlv_sticky_first( $hits ) {
	$sticky          = array();
	$nonsticky       = array();
	$sticky_post_ids = get_option( 'sticky_posts' );
	foreach( $hits[0] as $hit ) {
		if ( in_array( $hit->ID, $sticky_post_ids ) ) {
			$sticky[] = $hit;
		} else {
			$nonsticky[] = $hit;
		}
	}
	$hits[0] = array_merge( $sticky, $nonsticky );
	return $hits;
}

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Search results breakdown by type

Do you want to have a breakdown of search results by post type? This could be used for example to show a list of post types like books, movies, or albums on a review site, and make them links to limit the search results to that post type. This is…

Polylang attachment searching
If Polylang is in use and you haven’t enabled “Media translation“, your attachment files won’t have a language. That’s fine,…

Related Posts:

Comment Section:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed