ElasticPress ACF Fields

/**
 * Plugin Name: ElasticPress ACF Fields
 * Description: Register ACF Fields for search.
 * Version:     0.1.0
 * Author:      
 * Author URI:  
 * License:     
 *
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

\
/* Custom Fields to Return in the ElasticSearch Results */
function my_search_filter($query) {
    if ( !is_admin() && $query->is_main_query() ) {
      if ($query->is_search) {
       
          $query->set('search_fields', array(
          'post_title',
          'meta' => array( 
                        // Add Fields
                        'field_name',
                          
                          )));
      }
    }
  }
  add_action('pre_get_posts','my_search_filter',1);

Was this helpful?

Leave a Comment