Gists

5 months ago
<?php
/** adds images to the labels in an fselect **/

add_filter( 'facetwp_facet_display_value', function( $label, $params ) {

    if ( 'my_facet_name' == $params['facet']['name'] ) { // Replace "my_facet_name" with the name of your facet
        $term_id = $params["row"]["term_id"]; // get term_id
        $img = // lookup image for the term_id to create an img tag for output
        $img = esc_html( $img ); // esc_html is needed for fselects to have image html in them, otherwise the html is stripped from the display
        $label = $img . $label; // prepends image to label, use $label = $img; if you want to only display image in label
    }

    return $label;    

}, 10, 2 );
11 months ago
<?php

// Add to your (child) theme's functions.php

function wpml_compsupp6751_translate_facet_display_value( $label, $args ) {
    if ( class_exists('Sitepress') ) {
        $wpml_default_lang = apply_filters('wpml_default_language', NULL );
        $wpml_current_lang = apply_filters( 'wpml_current_language', NULL );

        if ($wpml_default_lang == $wpml_current_lang ) {
            do_action( 'wpml_register_single_string', 'FacetWP', 'Facet Display Value : '.substr($label, 0, 10), $label );
        }   
        // Apply the translation to the string
        $label = apply_filters('wpml_translate_single_string', $label , 'FacetWP', 'Facet Display Value : '.substr($label, 0, 10) );
    }
    return $label;
}
add_filter( 'facetwp_facet_display_value', 'wpml_compsupp6751_translate_facet_display_value', 10, 2 );
2 years ago
<?php

/**
 * Manually translate taxonomy terms
 * 
 * Change $facet_name
 * Change $tax_name
 */

add_filter( 'facetwp_facet_display_value', function( $label, $params ) {
    $facet_name = 'my_facet_name';
    $tax_name = 'my_tax_name';

	if ( $facet_name == $params['facet']['name'] ) {
		$current = ( !empty( FWP()->facet->http_params['lang'] ) ) ? FWP()->facet->http_params['lang'] :  apply_filters( 'wpml_current_language', null );  
		$default = apply_filters('wpml_default_language', NULL );
		if ( $current != $default ) {
			$translated_id = apply_filters( 'wpml_object_id', $params['row']['term_id'], $tax_name, TRUE, $current );
			$term = get_term( $translated_id );

			if ( ! empty( $term ) ) {
				$label = esc_html( $term->name );
			}
		}        
	}
	return $label;
}, 10, 2 );
3 years ago
<?php

// Change "categories" to the name of your facet

add_filter( 'facetwp_facet_display_value', function( $label, $params ) {
    if ( 'categories' == $params['facet']['name'] ) {
        $term = get_term_by( 'id', $params['row']['term_id'] );
        if ( ! empty( $term ) && ! empty( $term->description ) ) {
            $label = esc_html( $term->description );
        }
    }
    return $label;
}, 10, 2 );