Last active
August 25, 2020 16:00
-
-
Save djrmom/6d8c128bded058fde9da3b3f7c7a42b2 to your computer and use it in GitHub Desktop.
facetwp index checkbox saved as array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** index a serialized checkbox | |
** run reindex after adding code to your site | |
**/ | |
add_filter( 'facetwp_index_row', function( $params, $class ) { | |
if ( 'my_facet' == $params['facet_name'] ) { // change my_facet to name of your facet | |
$values = maybe_unserialize( $params['facet_value'] ); | |
if ( is_array( $values ) && ! empty( $values ) ) { | |
foreach ( $values as $value ) { | |
$new_params = $params; | |
$new_params['facet_value'] = $value; | |
$new_params['facet_display_value'] = $value; | |
$class->insert( $new_params ); // insert new value to the database | |
} | |
$params['facet_value'] = ''; // skip indexing, don't index original | |
} | |
} | |
return $params; | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment