Skip to main contentSkip to footer

Relevanssi can index extra fields created with Profile Builder Pro. All you need to do is add the custom fields’ names to the Relevanssi setting “User fields to index” (this is a Premium feature, so you need to have Relevanssi Premium). You can find the names of the fields from the Profile Builder > Manage Fields page: use the value in the “Meta Name” column.

Relevanssi doesn’t know how to use the extra fields in excerpts. This code adds all indexed fields to the user profile content before Relevanssi builds the excerpts using the relevanssi_pre_excerpt_content filter hook:

add_filter( 'relevanssi_pre_excerpt_content', 'rlv_profile_builder', 10, 2 );
function rlv_profile_builder( $content, $post ) {
    if ( isset( $post->user_id ) ) {
        $fields = get_option( 'relevanssi_index_user_fields' );
        if ( !empty( $fields ) ) {
            $fields_array = explode( ',', $fields );
            foreach( $fields_array as $user_field ) {
                $field_content = get_user_meta( $post->user_id, $user_field, true );
                $content .= ' ' . $field_content;
            }
        }
    }
    return $content;
}

Permalinks are another problem. By default, the permalinks in search results point to the site front page. Switching the permalinks on the theme search results template to use relevanssi_get_permalink() instead of get_permalink() or the_permalink() will help a bit, but not enough: now the links point to the WordPress user profile pages. However, Profile Builder Pro profile pages will use a different URL structure. Another filter function on the relevanssi_user_profile_to_post is needed:

add_filter( 'relevanssi_user_profile_to_post', 'rlv_adjust_url' );
function rlv_adjust_url( $user ) {
    $user->link = '/url/to/user/' . $user->user_id . '/';
    return $user;
}

Change the /url/to/user/ to match the URL structure used on your site. This change requires you to use relevanssi_get_permalink() to display the permalinks, the_permalink() or get_permalink() will not work.

Profiles created by Profile Builder Pro front end forms do not get automatically indexed by Relevanssi because the user account generation process in Profile Builder Pro doesn’t probably trigger all the filter hooks WP does. Thus Relevanssi overlooks the new user profiles Profile Builder Pro generates.

Profile Builder Pro has an action hook that you can use to nudge Relevanssi a bit. Add this code to your site, and Relevanssi will notice the new users and will index them:

add_action( 'wppb_register_success', 'rlv_index_wppb_users', 20, 3 );
function rlv_index_wppb_users( $http_request, $form_name, $user_id ){
    relevanssi_index_user( $user_id, false );
}

Your account

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

Search

Popular Resources

Gmedia photo gallery tags
Gmedia photo gallery gives a false impression of working with Relevanssi, as you can see the gmedia_tag taxonomy appear in…
Redirecting email searches to the login page

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……) ) { 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….

Category filter for search results pages

…$rlv_categories_present as $cat_id => $cat_name ) { $select .= “<option value=’$cat_id’>$cat_name</option>”; } $select .= “</select>”; $url = esc_url( remove_query_arg( ‘paged’ ) ); if ( false !== strpos( $url, ‘page’ ) ) { $url = preg_replace( ‘/page\/\d+\//’, ”, $url ); } $select .= <<<EOH <script> <!– var dropdown = document.getElementById(“rlv_cat”); function…Sometimes it’s nice to have a category filter on the search results pages: a simple dropdown where you can choose the category you want to show. It’s easy to create one using wp_dropdown_categories() but on a search results page, that’s slightly problematic, as it’ll include all categories, not just those……It’s a simple dropdown that lists the categories in alphabetical order (that comes from the asort() in the first function, actually) and includes a bit of JavaScript that adds a cat parameter with the correct value to the current URL and reloads the page. If a category parameter is already…

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