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

Excluding old content from the search

…* Adds a date filter to the search query. * * @param WP_Query $query The query object. * * @return WP_Query The modified query object. */ function rlv_date_filter( $query ) { $date_query = array( ‘after’ => ‘January 1st, 2016’, ‘inclusive’ => true, ); $query->set( ‘date_query’, $date_query ); return $query; }……) { global $wpdb; $restriction[‘mysql’] .= ” AND YEAR(post.post_date) >= 2016 “; $restriction[‘reason’] .= ‘ Post too old’; return $restriction; } Note that the restriction explains which posts are included in the index, so that’s why the year is >= 2016 and not < 2016. To deindex posts from the……$restriction[‘reason’] .= ‘ News post too old’; return $restriction; } If, on the other hand, you only want to apply this filter in searching, you can use the WP_Query date parameters like this: add_filter( ‘relevanssi_modify_wp_query’, ‘rlv_date_filter’ ); /** * Adds a date filter to the search query. * * @param…

Riode
Riode is a WooCommerce theme from ThemeForest. It has a built-in live search that does not automatically use Relevanssi. However,…

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