FacetWP – using the facetwp_indexer_post_facet filter

mgibbs189

{{gist file=”gistfile1.php” lang=”php”}}
<?php

function lh_fwp_index_coming_soon_facet( $return, $params ) {
$facet_params = $params[‘defaults’];
if ( ‘cf/edd_coming_soon’ == $facet_params[‘facet_source’] ) {
$value = get_post_meta( $facet_params[‘post_id’], ‘edd_coming_soon’, true );
$value = empty( $value ) ? ‘Available’ : ‘Coming Soon’;
$facet_params[‘facet_value’] = $value;
$facet_params[‘facet_display_value’] = $value;
FWP()->indexer->index_row( $facet_params );
return true; // we’re done indexing this facet
}
return $return;
}
add_filter( ‘facetwp_indexer_post_facet’, ‘lh_fwp_index_coming_soon_facet’, 10, 2 );
{{/gist}}