Posted on

Allowing decimal numbers

Relevanssi by default does not support decimal numbers. The decimal points are handled as punctuation and removed. If you want to keep decimal numbers together and make them available in the search, you can add this code to your theme functions.php:

add_filter('relevanssi_remove_punctuation', 'rlv_keep_decimals', 9);
function rlv_keep_decimals($a) {
	$a = preg_replace('/(\d)\./', '\1PERIOD', $a);
	return $a;
}
 
add_filter('relevanssi_remove_punctuation', 'rlv_keep_decimals_2', 11);
function rlv_keep_decimals_2($a) {
	$a = str_replace('PERIOD', '.', $a);
	return $a;
}

This will keep periods that come after numbers intact.

Leave a Reply

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