Last active
October 20, 2018 07:19
-
-
Save mgibbs189/6f4f98754a7c8ff5112b to your computer and use it in GitHub Desktop.
FacetWP - index multiple field values for a single autocomplete facet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Add to functions.php | |
| function fwp_combine_sources( $params, $class ) { | |
| if ( 'MY_FACET_NAME' == $params['facet_name'] ) { | |
| $value = get_field( 'YOUR_FIELD_1' ); | |
| $params['facet_value'] = sanitize_title( $value ); | |
| $params['facet_display_value'] = $value; | |
| $class->insert( $params ); | |
| $value = get_field( 'YOUR_FIELD_2' ); | |
| $params['facet_value'] = sanitize_title( $value ); | |
| $params['facet_display_value'] = $value; | |
| $class->insert( $params ); | |
| return false; // prevent default indexing | |
| } | |
| return $params; | |
| } | |
| add_filter( 'facetwp_index_row', 'fwp_combine_sources', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mgibbs189 I'm coming from this filter example for
facetwp_indexer_post_facetand now I wonder, isn't that one better performing for this purpose? At least to avoid querying taxonomies, post types or custom fields values that anyways are not going to be used by this facet.