📜  elasticpress acf (1)

📅  最后修改于: 2023-12-03 15:14:51.187000             🧑  作者: Mango

ElasticPress ACF

ElasticPress ACF is a WordPress plugin that enhances search functionality by integrating with the Advanced Custom Fields (ACF) plugin and the ElasticPress search engine.

Introduction

Many WordPress websites use Advanced Custom Fields (ACF) to create custom fields and store additional data. However, by default, the ElasticPress search engine cannot search for content within those custom fields. ElasticPress ACF solves this problem by indexing ACF fields and allowing you to search within them using the ElasticPress search engine.

Features
  • Support for all ACF field types.
  • Automatic indexing of all ACF fields.
  • Search within ACF fields in real-time.
  • Integration with ElasticPress search engine.
Requirements
  • WordPress 4.7+
  • Advanced Custom Fields (ACF) plugin
  • ElasticPress plugin
Installation
  1. Install and activate both the ElasticPress and ACF plugins.
  2. Install and activate the ElasticPress ACF plugin.
  3. Configure the plugin settings in the WordPress dashboard under ElasticPress ACF Settings.
Usage

Once the plugin is installed and activated, ACF fields will be automatically indexed by ElasticPress. You can now use the ElasticPress search engine to search within those fields. Here is an example of how to use ElasticPress ACF to search for content within a specific custom field:

$ep_query = new \ElasticPress\Elasticsearch\Query(
    [
        'query' => [
            'bool' => [
                'must' => [
                    [ 'match' => [ 'post_title' => 'Hello' ] ],
                    [ 'match' => [ 'meta.acf.field_name' => 'search_term' ] ],
                ],
            ],
        ],
    ]
);

$results = $ep_query->search();

foreach ( $results['hits']['hits'] as $result ) {
    echo $result['_source']['post_title'];
}
Conclusion

ElasticPress ACF is an essential plugin for websites that use Advanced Custom Fields (ACF) and the ElasticPress search engine. With this plugin, you can now search for content within all ACF fields using the powerful ElasticPress search engine.