FacetWP – Post Type Builder select/checkbox field indexing

mgibbs189

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

function index_ptb_select( $params, $class ) {
if ( 0 === strpos( $params[‘facet_source’], ‘cf/ptb_select’ ) ||
0 === strpos( $params[‘facet_source’], ‘cf/ptb_checkbox’ ) ) {

$option = PTB::get_option();
$cmb_options = $option->get_cpt_cmb_options( ‘property’ );
$ptb_field = str_replace( ‘cf/ptb_’, ”, $params[‘facet_source’] );

foreach ( (array) $params[‘facet_value’] as $val ) {
foreach ( $cmb_options as $k => $metabox ) {
if ( $ptb_field == $k && ! empty( $metabox[‘options’] ) ) {
foreach ( $metabox[‘options’] as $opt ) {
if ( $val == $opt[‘id’] ) {
$params[‘facet_value’] = $val;
$params[‘facet_display_value’] = $opt[‘de’];
$class->insert( $params );
}
}
}
}
}
return false; // prevent default indexing
}
return $params;
}
add_filter( ‘facetwp_index_row’, ‘index_ptb_select’, 10, 2 );
{{/gist}}