Title: FIltering specific visible custom fields
Last modified: June 23, 2017

---

# FIltering specific visible custom fields

 *  Resolved [bk2085](https://wordpress.org/support/users/bk2085/)
 * (@bk2085)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/filtering-specific-visible-custom-fields/)
 * I am running the CM Tooltips E-commerce plugin, which uses custom fields that
   are visible, but I don’t want to show in my search results. Is there a way to
   allow Relevanssi continue to index visible custom fields, but exclude few specific
   ones that I do not want indexed?

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * (@msaari)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/filtering-specific-visible-custom-fields/#post-9257339)
 * 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](https://wordpress.org/support/users/bk2085/)
 * (@bk2085)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/filtering-specific-visible-custom-fields/#post-9263578)
 * 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?
 *  Plugin Author [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * (@msaari)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/filtering-specific-visible-custom-fields/#post-9264242)
 * 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](https://wordpress.org/support/users/bk2085/)
 * (@bk2085)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/filtering-specific-visible-custom-fields/#post-9264285)
 * 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!
 *  [niemand_0](https://wordpress.org/support/users/niemand_0/)
 * (@niemand_0)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/filtering-specific-visible-custom-fields/#post-9306419)
 * 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](https://wordpress.org/support/users/niemand_0/).

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘FIltering specific visible custom fields’ is closed to new replies.

 * ![](https://ps.w.org/relevanssi/assets/icon-256x256.png?rev=3529670)
 * [Relevanssi - A Better Search](https://wordpress.org/plugins/relevanssi/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/relevanssi/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/relevanssi/)
 * [Active Topics](https://wordpress.org/support/plugin/relevanssi/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/relevanssi/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/relevanssi/reviews/)

 * 5 replies
 * 3 participants
 * Last reply from: [niemand_0](https://wordpress.org/support/users/niemand_0/)
 * Last activity: [8 years, 10 months ago](https://wordpress.org/support/topic/filtering-specific-visible-custom-fields/#post-9306419)
 * Status: resolved