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

User Access Manager

Relevanssi has a conflict with User Access Manager plugin. Both plugins attach to the same `the_posts` filter hook with the same priority, and if UAM runs after Relevanssi, it may cause some issues, like missing excerpts or even broken search results pages. The solution seems simple, however: at least in…

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