There's a plugin called ElasticPress it allows to connect an ElasticSearch server to WordPress. This plugin by default does not MAP Meta keys (custom fields) that begin with _ (underscore). But it has a filter to add any custom field to the mapping:
ep_prepare_meta_whitelist_key
My problem is that i don't understand how to use this filter to include my fields into the Mapping.
There's a plugin called ElasticPress it allows to connect an ElasticSearch server to WordPress. This plugin by default does not MAP Meta keys (custom fields) that begin with _ (underscore). But it has a filter to add any custom field to the mapping:
ep_prepare_meta_whitelist_key
My problem is that i don't understand how to use this filter to include my fields into the Mapping.
Share Improve this question asked Mar 21, 2019 at 22:16 Michael RogersMichael Rogers 5498 silver badges37 bronze badges1 Answer
Reset to default 4Solution 1
I haven't tested the plugin, but based on this code from the link in your question:
apply_filters( 'ep_prepare_meta_whitelist_key', false, $key, $post )
You can do something like this to explicitly allow a protected/private meta key:
add_filter( 'ep_prepare_meta_whitelist_key', function( $allow, $meta_key ){
$meta_keys = ['_one', '_two', '_etc']; // meta keys you want to allow
return in_array( $meta_key, $meta_keys );
}, 10, 2 );
Solution 2
Alternatively, looking at this part, you could use the ep_prepare_meta_allowed_protected_keys
filter to add your custom protected meta keys to the array of index-able private meta keys:
add_filter( 'ep_prepare_meta_allowed_protected_keys', function( $meta_keys ){
return array_merge( $meta_keys, ['_one', '_two', '_etc'] );
} );
Summary
If I were you, I'd use the second solution. But it's really up to you. :)
PS: The code would go in the theme functions file.