Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Created September 4, 2019 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchristopher/ab70357f0f942d9e9f28d4cc3b898cd8 to your computer and use it in GitHub Desktop.
Save jchristopher/ab70357f0f942d9e9f28d4cc3b898cd8 to your computer and use it in GitHub Desktop.
Tell SearchWP to index term names from ACF (Advanced Custom Fields) Taxonomy fields
<?php
// Tell SearchWP to index term names from ACF (Advanced Custom Fields) Taxonomy fields.
add_filter( 'searchwp_custom_fields', function( $meta_value, $meta_key, $the_post ) {
$acf_taxonomy_field_names = array( 'mytaxfield1', 'mytaxfield2' );
if ( ! in_array( $meta_key, $acf_taxonomy_field_names ) ) {
return $meta_value;
}
// Retrieve the value as per ACF's field settings.
$acf_field_object = get_field_object( $meta_key, $the_post->ID );
// We want to index the chosen terms names.
$meta_value = wp_list_pluck( $acf_field_object['value'], 'name' );
return $meta_value;
}, 20, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment