-
-
Save mgibbs189/6f4f98754a7c8ff5112b to your computer and use it in GitHub Desktop.
| <?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 ); |
I am working on a similar issue trying to add multiple results within a single facet... Did you get a resolution to this?
Thanks so much for this! FYI, I ran into an issue where get_field() was returning a NULL value inside the filter function. Eventually, I realized that I needed to grab the post ID from the params array, like this:
$value = get_field('YOUR_FIELD_1', $params['post_id']);
That solved my issue and it worked great after that. Hope that helps anyone who was experiencing the same issue.
@mgibbs189 I'm coming from this filter example for facetwp_indexer_post_facet and 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.
will this work with proximity facet type? I'm trying to pull latitude and longitude from 2 different fields, I've updated MY_FACET_NAME, YOUR_FIELD_1 & YOUR_FIELD_2 to reflect my facet and field names, search is not returning any results from this. Any idea what I could be missing?
// Add to functions.php
function fwp_combine_sources( $params, $class ) {
if ( 'proximityevents' == $params['facet_name'] ) {
$value = get_field( 'venue_lat' );
$params['facet_value'] = sanitize_title( $value );
$params['facet_display_value'] = $value;
$class->insert( $params );
$value = get_field( 'venue_lon' );
$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 );