Posted on

Indexing usermeta fields in Relevanssi

Relevanssi Premium can index user profiles. Users may have meta fields attached to them: there’s a wp_usermeta database table, even though the user editing interface by default doesn’t have any tools to add meta fields to users.

Codex includes documentation on how to use the user meta fields. Read Working with User Metadata for code examples. I’m sure there are also plugins that can help with this.

Relevanssi settings page doesn’t contain a setting for indexing user meta fields. There’s, however, a hidden option you can use to index user custom fields. You can either set the option or use the pre_option_ filter hook to feed it.

Let’s say you want to index three custom fields: field_A, field_B and field_C. Add one of these functions to your site and rebuild the index to index the custom fields:

add_filter('pre_option_relevanssi_index_user_meta', 'rlv_index_user_meta_fields'); 
function rlv_index_user_meta_fields( $value ) { 
    return 'field_A,field_B,field_C';
}

or simply:

update_option( 'relevanssi_index_user_meta', 'field_A,field_B,field_C' );

2 comments Indexing usermeta fields in Relevanssi

Leave a Reply

Are you a Relevanssi Premium customer looking for support? Please use the Premium support form.

Your email address will not be published. Required fields are marked *