Hi,
When setting public post meta keys to index you have a hook to only exclude keys 'ep_prepare_meta_excluded_public_keys'. I have posts with over 40 postmeta fields and only wish to index a few. A hook allowing which keys to include would be very helpful and to be honest feels less counter-intuitive.
I added my own but obviously would make sense to have it in the core.
Its a simple change that complements the existing exclude hook.
Note i also added a third arg array_keys($meta) which i believe is also v helpful
Thanks for the plugin.
class EP_API
$allowed_public_keys = apply_filters( 'ep_prepare_meta_allowed_public_keys', false, $post, array_keys($meta));
foreach ( $meta as $key => $value ) {
$allow_index = false;
if ( is_protected_meta( $key ) ) {
if ( true === $allowed_protected_keys || in_array( $key, $allowed_protected_keys ) ) {
$allow_index = true;
}
} else {
//*****************************************************************************
if ( true === $allowed_public_keys || in_array( $key, $allowed_public_keys ) ) {
$allow_index = true;
}
//*****************************************************************************
if ( true !== $excluded_public_keys && ! in_array( $key, $excluded_public_keys ) ) {
$allow_index = true;
}
}
if ( true === $allow_index || apply_filters( 'ep_prepare_meta_whitelist_key', false, $key, $post ) ) {
$prepared_meta[ $key ] = maybe_unserialize( $value );
}
}
Feel free to open a PR.
Can someone please write an example of how to use ep_prepare_meta_whitelist_key filter to index some meta keys? I can't figure it out by looking at it.
Most helpful comment
Can someone please write an example of how to use ep_prepare_meta_whitelist_key filter to index some meta keys? I can't figure it out by looking at it.