Gists

by djrmom - 4 weeks ago

<?php
/** return custom data in the json facet returns on refresh
 ** access with FWP.settings.my_data in JS
 */
add_filter( 'facetwp_render_output', function( $output, $params ) {
    $output['settings']['my_data'] = 'some data';
    return $output;
}, 10, 2 );
by djrmom - 9 months ago

<?php
/** custom number format for a slider facet
 ** change_me needs to be changed to the name of the slider facet
 **/

add_filter( 'facetwp_render_output', function( $output, $params ) {
	if ( isset( $output['settings']['change_me'] ) ) {
		$output['settings']['change_me']['format'] = '0,0.0000';
	}
	return $output;
}, 10, 2 );
by mgibbs189 - 1 year ago

<?php

add_filter( 'facetwp_render_output', function( $output, $params ) {
    $output['settings']['post_ids'] = FWP()->facet->query_args['post__in'];
    return $output;
}, 10, 2 );

by mgibbs189 - 1 year ago

<?php

/**
 * Modify the output HTML and highlighting all search terms
 */
add_filter( 'facetwp_render_output', function( $output, $params ) {
    $keywords = '';

    if ( isset( FWP()->facet['keywords'] ) ) {
        $keywords = FWP()->facet['keywords']['selected_values'];
        $keywords = is_array( $keywords ) ? implode( ' ', $keywords ) : $keywords;
    }

    if ( ! empty( $keywords ) && class_exists( 'SearchWPHighlighter' ) ) {
        $highlighter = new SearchWPHighlighter();
        $output['template'] = $highlighter->apply_highlight( $output['template'], $keywords );
    }
    return $output;
}, 10, 2 );

by djrmom - 1 year ago

<?php
/** set a custom range for a slider facet and set
 ** the start and end handles to the min/max of range instead of
 ** the min/max of the indexed data
 **/
add_filter( 'facetwp_render_output', function( $output, $params ) {
	if ( isset( $output['settings']['price'] ) ) {
		$output['settings']['price']['range'] = array(
			'min' => array( 0 ),
			'max' => array( 40000 )
		);
		$output['settings']['price']['start'] =  array( 0, 40000 );
	}
	return $output;
}, 10, 2 );
by djrmom - 2 years ago

<?php
/** set a custom range for a slider facet **/
add_filter( 'facetwp_render_output', function( $output, $params ) {
	if ( isset( $output['settings']['YOUR_SLIDER_FACET_NAME'] ) ) {
		$output['settings']['YOUR_SLIDER_FACET_NAME']['range'] = array(
			'min' => array( 0 ),
			'max' => array( 40,000 )
		);
	}
	return $output;
}, 10, 2 );
by mgibbs189 - 2 years ago

add_filter( 'facetwp_render_output', function( $output ) {
    $output['settings']['location']['numDisplayed'] = 1;
    return $output;
});
by mgibbs189 - 2 years ago

<?php

add_filter( 'facetwp_render_output', function( $output ) {
    $output['settings']['YOUR_FACET_NAME']['showSearch'] = false;
    return $output;
});

by mgibbs189 - 3 years ago

<?php

add_filter( 'facetwp_render_output', function( $output ) {
    $output['settings']['YOUR_FACET_NAME']['searchText'] = 'Hello world';
    return $output;
});

by mgibbs189 - 3 years ago

<?php

// Generate the pager on pageload
add_filter( 'facetwp_render_params', function( $params ) {
    $params['extras']['pager'] = true;
    return $params;
});

// Store the pager variable
add_filter( 'facetwp_render_output', function( $output, $params ) {
    FWP()->pager_html = $output['pager'];
    return $output;
}, 10, 2 );

// IN TEMPLATE: output pager
echo FWP()->pager_html;