Skip to main contentSkip to footer

A surprisingly common problem with Relevanssi is Bible verses. All that meaningful punctuation and single digits make exact matching of Bible verses really difficult for Relevanssi, and when searching for Bible verses, exact results are what matters – hitting something similar is generally not very helpful.

There’s an easy solution, though: use phrases. Wrapping the verse in quotes is going to result in an exact search that finds exactly what is required. Unfortunately expecting all your users to know that is not reasonable. Most users don’t even know what a phrase search is, let alone that you should use one for Bible verses.

The fix is simple: add some code that will automatically wrap all the Bible verse in quotes to make it a phrase. Add this to your theme functions.php and enjoy more precise Bible verse searches:

add_filter( 'relevanssi_modify_wp_query', 'rlv_bible_verse_handler' );
function rlv_bible_verse_handler( $query ) {
    $m = preg_match_all( '/(\d?\s?\w+ \d+:\d+-?\d?)/', $query->query_vars['s'], $matches );
    if ( $m ) {
        foreach ( $matches[0] as $match ) {
            $query->query_vars['s'] = str_replace( trim($match), '"' . trim($match) . '"', $query->query_vars['s'] );
        }
    }
    $query->query_vars['s'] = str_replace( '""', '"', $query->query_vars['s'] );
    return $query;
}

Your account

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

Search

Popular Resources

Filtering results by category

…you want to. Remember that whenever you link to search results like that, it’s a good idea to tell Google and other bots to avoid indexing the results. The link above has the “rel=’nofollow’” instruction, but you can also use robots.txt to prevent bots from spidering your search results pages….In order to filter search results by category, use the following code: $url = get_bloginfo(‘url’); $url = esc_attr(add_query_arg(array(‘cat’ => ’10’, ‘s’ => get_search_query()), $url)); echo “Filter by category 10”; Put this in your search results template. What the code does is to create a link that takes the current search……query and adds the category variable to it. This link filters the results by category 10, change the number to correct category ID to make it filter by the category you want to. Remember that whenever you link to search results like that, it’s a good idea to tell Google…

OceanWP
OceanWP is a popular WordPress theme. It works fine with Relevanssi, but how it handles excerpts on the search results…

Related Posts:

Comment Section:

1 Comment. Leave new

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