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

CM Tooltip Glossary

A Relevanssi Premium customer bumped into a weird problem with CM Tooltip Glossary (and probably Elementor). Using Elementor, CM Tooltip Glossary and Relevanssi custom excerpts together caused the search results to break in an unusual way: each page of the search results showed the same results. I couldn’t figure out…

Index only short numbers
Relevanssi has a minimum word length setting that is set to three characters. Any one- or two-letter words are not…

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