facetwp WPJM field editor checkbox

djrmom

{{gist file=”custom-hooks.php” lang=”php”}}
<?php

/** set your facet to use the Post Type as the datasource, this is just a placeholder to make sure it is being indexed
** the filter will then check and index the value of the post meta
** ‘job_check’ is the facet name change as needed
** ‘_job_check’ is the custom meta key name, make sure you are checking the correct meta key
**/

add_filter( ‘facetwp_index_row’, function( $params, $class ) {
if ( ‘job_check’ == $params[‘facet_name’] && ‘job_listing’ == get_post_type( $params[‘post_id’] ) ) {
if ( ‘1’ === get_post_meta( $params[‘post_id’], ‘_job_check’, true ) ) {
$params[‘facet_value’] = ‘1’;
$params[‘facet_display_value’] = ‘Yes’;
} else {
$params[‘facet_value’] = ‘0’;
$params[‘facet_display_value’] = ‘No’;
}
} else {
$params[‘facet_value’] = ”; // skip indexing
}
return $params;
}, 10, 2);
{{/gist}}