Skip to main contentSkip to footer

If you want to add an option to search only in titles to your search form, here’s how. First, you need to modify the search form to add the selection. To add a simple dropdown, add this to your search form:

<select name="titles">
  <option value="0">Search Everything</option>
  <option value="1">Search only in Titles</option>
</select>

This select element will create a small dropdown with the option to search everything or only in titles. It will set the titles query parameter to 0 or 1, depending on the user selection. We can then look for that parameter and when the parameter value is 1, ignore everything that isn’t a title match.

add_filter(
	'relevanssi_match',
    function( $match ) {
		if ( 1 === intval( $_GET['titles'] ) ) {
			if ( $match->title < 1 ) {
				$match->weight = 0;
			}
		}
  		return $match;
	}
);

This function will set the match weight to 0 if the word doesn’t match a title.

Your account

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

Search

Popular Resources

Unyson
Unyson is a free drag & drop framework. It stores the content in a custom field fw:opt:ext:pb:page-builder:json. While Relevanssi can…
Avada
Avada is one of the most popular WordPress themes on the market. All post types are not found Avada has…
FileBird: Filtering attachments by folder

…Once you add this, you can use the folder parameter to restrict the search to a specific folder. The search ?s=search+term&folder=42 would only return attachments that are in folder 42. It’s possible to build more complex filtering, too; this should give you an idea of how the folder information can…FileBird is one of many WordPress plugins that provide more control over the attachments in the Media Library. You can use the FileBird folders in Relevanssi searches to filter attachments based on their folder. Here’s a simple function you can add to your site: add_filter( ‘relevanssi_hits_filter’, function( $hits ) {…

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