Gists

1 month ago
<?php

add_filter( 'facetwp_facet_render_args', function( $args ) {
    if ( 'program_days' == $args['facet']['name'] ) {
        $lookup = [];
        $temp_values = [];
        $days = [ 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday' ];

        foreach ( $args['values'] as $row ) {
            $lookup[ $row['facet_value'] ] = $row;
        }

        foreach ( $days as $day ) {
            if ( isset( $lookup[ $day ] ) ) {
                $temp_values[] = $lookup[ $day ];
            }
            else {
                $temp_values[] = [
                    'facet_value' => $day,
                    'facet_display_value' => ucfirst( $day ),
                    'counter' => 0
                ];
            }
        }

        $args['values'] = $temp_values;
    }

    return $args;
});
4 years ago
<?php

add_filter( 'facetwp_facet_render_args', function( $args) {
	if ( 'my_search_facet' == $args['facet']['name'] ) {  // change my_search_facet to name of your facet
		$args['facet']['placeholder'] = 'Something';
	}
	return $args;
} );
4 years ago
//filter color display to maybe add hash to hex colors
add_filter( 'facetwp_facet_render_args', function( $args ) {
	if ( 'colors' == $args['facet']['name'] ) {
	    foreach ( $args['values'] AS $key => $value ) {
	        $args['values'][$key]['facet_display_value'] = ( '' != ( $color = sanitize_hex_color_no_hash( $value['facet_display_value'] ) ) ) ? '#' . $color : $value['facet_display_value'];
        }
	}
	return $args;
});

//filter color index to maybe add hash to hex colors
add_filter( 'facetwp_index_row', function( $params ) {
	if ( 'colors' == $params['facet_name'] ) {
		$display_value = $params['facet_display_value'];
		$params['facet_display_value'] = ( '' != ( $color = sanitize_hex_color_no_hash( $params['facet_display_value'] ) ) ) ? '#' . $color : $params['facet_display_value'];
	}
	return $params;
}, 10 );