Skip to main contentSkip to footer

A client asked for a solution to redirect all searches for email addresses to the login page – perhaps someone is constantly using the search field when they’re actually looking for the login.

This can be achieved with the Redirects tool, as it takes regular expressions. You can also add this to your site:

add_action( 'template_redirect', 'rlv_redirect_emails' );
function rlv_redirect_emails() {
    if ( filter_var( get_search_query(), FILTER_VALIDATE_EMAIL ) ) {
        if ( wp_redirect( 'https://www.example.com/wp-login.php' ) ) {
            exit();
        }
    }
}

This function would redirect all queries that look like email addresses (based on RFC 822, with some caveats) to the login page on example.com.

There’s nothing Relevanssi-specific about this, this same function will work with any search solution that isn’t an AJAX search.

Your account

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

Search

Popular Resources

German umlauts
By default, the search ignores German umlauts. Searching for “uber” will also find “über” and so on. This ignorance is…
How to index parent categories

…this does not work, because Relevanssi doesn’t index parent categories for posts, just the category attached to the post. However, Relevanssi is about control, so this can be done using the relevanssi_content_to_index filter hook. Add the following code to functions.php of your theme and re-index: add_filter( ‘relevanssi_content_to_index’, ‘rlv_parent_categories’, 10, 2…Suppose you have a parent category with no products in it but a child category does. If you search by the parent category can relevanssi be set up to show the products in the child category? Cars > Wiper Blades. A search for cars shows wiper blade products. By default…

Results are in strange order
If best results don’t come up first and changing weighting settings doesn’t seem to make any difference, there couple of…

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