Gists

3 months ago
<?php
/** this error occurs when there are no available dates for the calendar picker
 ** to display, changing from 0 to "" fixes the calendar but 
 ** actual dates could be used for min/max if preferred, see
 ** https://facetwp.com/help-center/developers/hooks/output-hooks/facetwp_render_output/#customize-a-date-range-facets-date-picker-range
 ** all 4 of these checks may not be needed if both dates are
 ** to configured to display
 **/

// Replace "bad_dates" with the name of your Date Range facet
add_filter( 'facetwp_render_output', function( $output, $params ) {

    if ( isset( $output['settings']['bad_dates'] ) ) {
        if ( 0 == $output['settings']['bad_dates']['range']['min']['minDate'] ) {
            $output['settings']['bad_dates']['range']['min']['minDate'] = ''; // start date min
        }
        if ( 0 == $output['settings']['bad_dates']['range']['min']['maxDate'] ) {
            $output['settings']['bad_dates']['range']['min']['maxDate'] = ''; // start date max
        }
        if ( 0 == $output['settings']['bad_dates']['range']['max']['minDate'] ) {
            $output['settings']['bad_dates']['range']['max']['minDate'] = ''; // End date min
        }
        if ( 0 == $output['settings']['bad_dates']['range']['max']['maxDate'] ) {
            $output['settings']['bad_dates']['range']['max']['maxDate'] = ''; // End date max
        }
    }

    return $output;
  }, 10, 2 );
6 months ago
<?php
add_filter( 'facetwp_render_output', function( $output, $params ) {
    if ( FWP()->ajax->is_preload && isset( $output['settings']['map']['locations'] ) ) {
        $output['settings']['map']['locations'] = [];
    }
    return $output;
}, 11, 2 );
1 year ago
<?php
// Each facet's source now can be accessed in JavaScript with FWP.settings.facet_sources['your_facet_name']

add_filter( 'facetwp_render_output', function( $output, $params ) {
  $sources = [];

  foreach ( FWP()->facet->facets as $facet_name => $facet_data ) {
    if ( isset ( $facet_data['source'] ) ) {
      $sources[ $facet_name ] = $facet_data['source'];
    }
  }

  $output['settings']['facet_sources'] = $sources;
  return $output;
}, 10, 2 );
2 years ago
<?php

add_filter( 'facetwp_render_output', function( $output ) {
    $facets = FWP()->helper->get_facets();
    foreach ( $facets as $facet ) {
        if ( 'fselect' == $facet['type'] ) {
            $output['settings'][ $facet['name'] ]['showSearch'] = false;
        }
    }
    return $output;
});
3 years ago
<?php

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

// To access the post IDs, type "FWP.settings.post_ids" into the browser console
3 years ago
<?php

// Add to your (child) theme's functions.php
// replace "YOUR_FACET_NAME" with your *actual* facet name

add_filter( 'facetwp_render_output', function( $output ) {
    $output['settings']['YOUR_FACET_NAME']['range']['min']['minDate'] = date( 'Y-m-d' );
    return $output;
});
2 years ago
<?php
/**
 ** use label instead of showing selected values in fselect
 ** replace "role" with the actual facet name, and "Please select Role" with the text you want to use
 **/

add_filter( 'facetwp_render_output', function( $output ) {
    if ( isset( $output['settings']['role'] ) ) {
        $output['settings']['role']['overflowText'] = 'Please select Role';
        $output['settings']['role']['numDisplayed'] = 0;
    }
    return $output;
});
2 years ago
<?php
/** translate text strings for use with the date range facet **/
add_filter( 'facetwp_render_output', function( $output, $params ) {
    if ( isset( $output['settings']['my_date_range'] ) ) {
        $output['settings']['my_date_range']['locale'] = [
            'weekdays_short' => ['Dg', 'Dl', 'Dt', 'Dc', 'Dj', 'Dv', 'Ds'], // abbreviations for Sun to Sat
            'months_short' => ['Gen', 'Febr', 'Març', 'Abr', 'Maig', 'Juny', 'Jul', 'Ag', 'Set', 'Oct', 'Nov', 'Des'], // abreviations for months Jan to Dec
            'months' => ['Gener', 'Febrer', 'Març', 'Abril', 'Maig', 'Juny', 'Juliol', 'Agost', 'Setembre', 'Octubre', 'Novembre', 'Desembre'],  //full names for months Jan to Dec
            'firstDayOfWeek' => 1, // 1 is Monday, 0 is Sunday
			'clearText' => 'Clear' // text for clear button
        ];
    }
    return $output;
}, 10, 2 );
1 year ago
<?php

// Add to your (child) theme's functions.php
// replace "YOUR_FACET_NAME" with your *actual* facet name

add_filter( 'facetwp_render_output', function( $output ) {
    $output['settings']['YOUR_FACET_NAME']['range']['min']['minDate'] = '2021-03-21';
    $output['settings']['YOUR_FACET_NAME']['range']['min']['maxDate'] = '2021-12-31';
    return $output;
});
4 years ago
<?php

// Add to your (child) theme's functions.php
// @link https://docs.wp-rocket.me/article/90-getrocketcdnurl

add_filter( 'facetwp_render_output', function( $output, $params ) {
    if ( function_exists( 'get_rocket_cdn_url' ) ) {
        $html = $output['template'];
        $html = str_replace( get_home_url(), get_rocket_cdn_url( get_home_url() ), $html );
        $output['template'] = $html;
    }
    return $output;
}, 10, 2 );