Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.