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

Pin a post for all searches
Relevanssi Premium has tools for pinning posts for specific queries and all searches where the post appears, but what if…
Elementor

…a Query ID in the Elementor settings and then add this to your site: add_action( ‘elementor/query/YOUR_QUERY_ID’, function( $query ) { $query->set( ‘relevanssi’, true ); } ); This will make that specific query use Relevanssi. Using Relevanssi with Elementor Live Results Elementor has a feature for custom Query Filters. These can……be used to connect Relevanssi with the Elementor Live Results and the Elementor Search Widget. First, you need to add this function to your site: function my_relevanssi_results( $query ) { $query->set( ‘relevanssi’, true ); $query->set( ‘orderby’, ‘relevance’ ); } add_action( ‘elementor/query/my_relevanssi_results’, ‘my_relevanssi_results’ ); Then, follow these instructions from Elementor: Assuming…Elementor is a popular page builder. It works rather well with Relevanssi, most of the time. Check for e_search_props If the search results come back empty or are restricted to a specific post type, it’s possible Elementor is restricting them. Elementor can hide the query parameters to a single query…

User Access Manager
Relevanssi has a conflict with User Access Manager plugin. Both plugins attach to the same `the_posts` filter hook with the…

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