facetwp index a value indicating a field is set instead of the field

djrmom

{{gist file=”custom-hooks.php” lang=”php”}}
<?php
/** instead of indexing the value of a field, index a value and label to indicate the custom field exists for that post **/

add_filter( ‘facetwp_index_row’, function( $params, $class ) {
if ( ‘my_facet’ == $params[‘facet_name’] ) { // change my_facet to the name of your facet
if (!empty( $params[‘facet_display_value’] ) ) {
$params[‘facet_value’] = ‘true’; // this will be the value in the filter url
$params[‘facet_display_value’] = ‘Has Value’; // this is the label you want the facet to show
} else {
$params[‘facet_value’] = ”; // don’t index is value is blank
}
}
return $params;
}, 10, 2 );
{{/gist}}