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

Indexing embedded PDFs for the parent post

…10 ); function rlv_algoriviever_content( $block ) { if ( $block[‘blockName’] === ‘algori-pdf-viewer/block-algori-pdf-viewer’ ) { $block[‘innerContent’] = array( get_post_meta( $block[‘attrs’][‘id’], ‘_relevanssi_pdf_content’, true ) ); } return $block; } PDF Content in Excerpts To get excerpts from the PDF content, you can use the same function with the relevanssi_excerpt_content]}** filter hook, like…this: add_filter( ‘relevanssi_excerpt_content]}**’, ‘rlv_pdfjs_content’, 10, 2 ); This function will include the PDF content for excerpt-building. There’s a performance cost, so you have to try and see whether including the content slows down the search too much. One option is to read the PDF content to a custom field in…File block from WordPress, this snippet will index the PDF contents for the post where the file is embedded: add_filter( ‘relevanssi_block_to_render’, function( $block ) { if ( ‘core/file’ === $block[‘blockName’] ) { $file_id = $block[‘attrs’][‘id’]; $file_content = get_post_meta( $file_id, ‘_relevanssi_pdf_content’, true ); if ( $file_content ) { $block[‘innerContent’][0] = $file_content;

Korean postpositions
Korean has postpositions, which complicate things for Relevanssi. Fortunately, it’s easy to clean up the most common postpositions from the…

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