Last active
August 2, 2017 17:35
-
-
Save DavidCramer/6e937a27970e3628da94669d425995e3 to your computer and use it in GitHub Desktop.
custom radio facet html
This file contains 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 | |
add_filter( 'facetwp_facet_html', function( $output, $params ) { | |
if ( 'my_facet' == $params['facet']['name'] ) { | |
$output = ''; | |
$values = (array) $params['values']; | |
$selected_values = (array) $params['selected_values']; | |
foreach( $values as $result ){ | |
$clean_val = esc_attr( $result ); | |
$selected = in_array( $result['facet_value'], $selected_values ) ? ' checked' : ''; | |
$selected .= ( 0 == $result['counter'] && '' == $selected ) ? ' disabled' : ''; | |
$output .= '<div class="facetwp-radio' . $selected . '" data-value="' . $clean_val . '">'; | |
$output .= '<img src="url_to_image/' . $clean_val . '.svg" alt="' . $clean_val . '"> ' . $result['counter']; | |
$output .= '</div>'; | |
} | |
} | |
return $output; | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment