最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - ElasticPress how to Include Meta to the mapping?

programmeradmin2浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 4

Solution 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.

发布评论

评论列表(0)

  1. 暂无评论