Skip to content

Instantly share code, notes, and snippets.

@djrmom
djrmom / facet.html
Last active November 18, 2020 04:41
facetwp cars demo radio buttons
<style>
.facetwp-facet.facetwp-facet-vehicle_type {
margin-bottom: 0;
}
.facetwp-facet-vehicle_type .facetwp-radio {
display: inline-block;
background: none;
line-height: 48px;
width: 120px;
margin: 0;
@djrmom
djrmom / custom-hooks.php
Last active April 19, 2018 16:21
facetwp check main query with uri
<?php
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( 'residents' == FWP()->helper->get_uri() && 'resident' != $query->get( 'post_type' ) ) {
return false;
}
return $is_main_query;
}, 10, 2 );
<?php
/* convert state into region */
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'region' == $params['facet_name'] ) {
$northwest = array( 'WA', 'OR', 'MT');
$northeast = array( 'ME', 'VT', 'MA', 'NH' );
$raw_value = $params['facet_value'];
if ( in_array( $raw_value, $northwest ) ) {
(function($) {
$(document).on('facetwp-loaded', function() {
if ( $().isotope ) {
var $container = $( '#tribe-events-photo-events' )
$container.isotope({
itemSelector: '.tribe-events-photo-event',
percentPosition: true,
masonry: {
@djrmom
djrmom / custom-hooks.php
Last active August 25, 2020 16:00
facetwp index only parent and one level child terms
<?php
/**
** only index parent and first level child tax terms
** must re-index after adding filter
**/
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'my_tax_facet' == $params['facet_name'] && $params['depth'] > 1 ) { // channge 'my_tax_facet' to the facet name being indexed
$params['facet_value'] = ''; // skip indexing
}
@djrmom
djrmom / preselect-current-day.php
Last active January 12, 2018 18:44 — forked from anonymous/preselect-current-day.php
facetwp - Attempt to preload the days events using a specific link
<?php
// Attempt to preload the days events using a specific link
// Link URL should be structured this way http://mercerspace.com/events/?today=true
function fwp_preload_facets( $url_vars ) {
if( 'events' == FWP()->helper->get_uri() && isset( $_GET['today'] ) && empty( $url_vars ) ) {
$url_vars['event_dates'] = array( date( "Y-m-d" ) );
}
return $url_vars;
}
@djrmom
djrmom / scripts.js
Created January 8, 2018 22:06
facetwp check FWP in js
<script>
(function($) {
$(function() {
if ( 'undefined' !== typeof FWP ) {
// Make checkbox options semi-transparent
FWP.loading_handler = function(params) {
params.element.find('.facetwp-checkbox').css('opacity', 0.5);
}
}
});
@djrmom
djrmom / custom-hooks.php
Created January 9, 2018 00:18
facetwp auto-check facet
<?php
function fwp_update_facets() {
?>
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
if ( 'trainings-finden' == FWP_HTTP.uri ) {
if ( FWP.facets['standort'].indexOf("aarau") > -1 && ! ( FWP.facets['standort'].indexOf("flexibel") > -1 ) ) {
FWP.is_reset = true;
@djrmom
djrmom / custom-hooks.php
Created January 9, 2018 17:25
facewp detect query
<?php
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( !in_array( 'hotel', $query->get( 'post_type' ) ) ) {
$is_main_query = false;
}
return $is_main_query;
}, 10, 2 );
@djrmom
djrmom / custom-hooks.php
Created January 9, 2018 19:16
facetwp facetwp_query_args shortcode template filter
<?php
add_filter( 'facetwp_query_args', function( $query_args, $class ) {
if ( 'gluten_free' == $class->ajax_params['template'] && 'gluten-free-everywhere' == $class->http_params['uri'] ) {
$query_args['tax_query'] = array(
array(
'taxonomy' => 'category', // change 'category' to different taxonomy if needed
'field' => 'slug',
'terms' => array( 'entertainment', 'travel', 'breakfast-box', 'lunchbox', 'gluten-free-guides' ) // array of term slugs
)