Yes: the list of custom fields is passed through the relevanssi_index_custom_fields filter hook. The filter hook gets an array of custom field names as the parameter, you can remove the ones you don’t like and return the rest.
add_filter('relevanssi_index_custom_fields', 'rlv_skip_custom_fields');
function rlv_skip_custom_fields($custom_fields) {
$unwanted_fields = array('not_this_field', 'this_one_either');
$custom_fields = array_diff($custom_field, $unwanted_fields);
return $custom_fields;
}
Thread Starter
bk2085
(@bk2085)
Thank you Mikko.
I can’t seem to get this solution to work, but let me make sure I’m following you correctly.
I added the following:
add_filter('relevanssi_index_custom_fields', 'rlv_skip_custom_fields');
function rlv_skip_custom_fields($custom_fields) {
$unwanted_fields = array('cmtt_synonyms', 'cmtt_variations');
$custom_fields = array_diff($custom_field, $unwanted_fields);
return $custom_fields;
}
In this example, I want to filter/prevent the custom fields cmtt_synonyms and cmtt_variations from appearing in my search results. I added that filter and then reindexed, but they are still appearing in my search results. Did I miss anything?
You’ve got the wrong variable name in there:
$custom_fields = array_diff($custom_field, $unwanted_fields);
Should be $custom_fields, not $custom_field.
Thread Starter
bk2085
(@bk2085)
Thank you, Mikko. I changed that, resulting in the code below. I then reindexed, but the same custom fields are appearing in my snippets. Any other ideas?
add_filter('relevanssi_index_custom_fields', 'rlv_skip_custom_fields');
function rlv_skip_custom_fields($custom_fields) {
$unwanted_fields = array('cmtt_synonyms', 'cmtt_variations');
$custom_fields = array_diff($custom_fields, $unwanted_fields);
return $custom_fields;
}
Thank you!
Do a var_dump($custom_fields) to make sure the strings in your $unwanted_fields array are actually the field names being used in $custom_fields.
You’ll see the result of the var_dump() on the Relevanssi admin page when you reindex.
-
This reply was modified 8 years, 10 months ago by
niemand_0.