Gists

2 weeks ago
<?php

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

add_action( 'wp_head', function() {
?>
<script>
document.addEventListener('facetwp-refresh', function() {
    delete FWP.frozen_facets['sort_by'];
});
</script>
<?php
}, 100 );
3 months ago
<?php

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

add_action( 'wp_head', function() {
?>
<script>
document.addEventListener('facetwp-refresh', function() {
    if (! FWP.loaded) {
        FWP.hooks.addAction('facetwp/loaded', function() {
            fUtil('.facetwp-type-fselect .facetwp-dropdown').each(function() {
                fUtil(this).nodes[0].fselect.close();
            });
        }, 20);
    }
});
</script>
<?php
}, 100 );
1 month ago
<?php
/** adds script to header 
 **/
add_action( 'wp_head', function() { ?>
	<script>
		(function($) {
        $(document).on('facetwp-refresh', function() {
            if (FWP.loaded && 'recipes' != FWP_HTTP.uri) { // if not the initial pageload, and we're on the homepage
                window.location.href = '/recipes/?' + FWP.buildQueryString(); // redirect
            }
        });
    })(jQuery);
	</script>
<?php } );
1 year ago
<script>
(function($) {
    $(document).on('facetwp-refresh', function() {
        if (! FWP.loaded) {
            FWP.temp_set_hash = FWP.set_hash; // on init, save a backup of FWP.set_hash()
        }
        if (FWP.is_reset) {
            FWP.set_hash = FWP.temp_set_hash; // on reset, store FWP.set_hash()
        }
        else {
            FWP.set_hash = function() { /* empty */ } // otherwise, empty it
        }
    });
})(jQuery);
</script>
1 year ago
(function($) {
    $(document).on('facetwp-refresh', function() {
      if ( 'undefined' !== typeof FWP.facets['facet_1'] && FWP.facets['facet_1'].length > 0 ) {
          FWP.facets['facet_2'] = FWP.facets['facet_1'];
          FWP.facets['facet_1'] = [];
      }
    });
})(jQuery);
2 years ago
<?php
/** sample of css and js to create a custom loading animation to cover the full facet area
 ** change #facet-container to a id or class of container element for your facets
 ** update css as needed
 ** please see https://facetwp.com/documentation/support/ for questions
 **/

add_action( 'wp_head', function() { ?>
    <style>
		#facet-container {
			position: relative;
		}
		.custom-loader {
			position: absolute;
			background-image: url("/path/to/image");
			background-position: center;
			background-repeat: no-repeat;
		}
    </style>
<?php });

add_action( 'wp_head', function() {
	?>
	<script>
	(function($) {
		$(document).on('facetwp-refresh', function() {
			if (FWP.loaded) {
				$('#facet-container').prepend('<div class="custom-loader facetwp-loading"></div>');
				$('.custom-loader').height( $('#facet-container').height() ).width( $('#facet-container').width() );
			}
		});
	
		$(document).on('facetwp-loaded', function() {
			$('.custom-loader').remove();
		});
	})(jQuery);  
	</script>
	<?php
},100);
5 months ago
<?php

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

add_action( 'wp_head', function() {
?>
<script>
(function($) {
    $(document).on('facetwp-refresh', function() {
        if (! FWP.loaded) {
            FWP.setHash = function() { /* empty */ }
        }
    });
})(jQuery);
</script>
<?php
}, 100 );
2 years ago
<?php
/** conditionally change templates on ajax refresh, only works for use with facetwp
 ** layout builder templates
 **/
add_action( 'wp_footer', function() {
	?>
    <script>
        (function($) {
            $(document).on('facetwp-refresh', function() {
                if ( 'undefined' !== typeof FWP.facets['categories'] && FWP.facets['categories'].length > 0 ) {
                    FWP.template = 'example_2';
                } else {
                    FWP.template = 'example';
                }
            });
        })(jQuery);
    </script>
	<?php
}, 100 );
9 months ago
<?php
/** adds the post_id to a variable passed during refresh **/
add_action( 'wp_footer', function() {
    if ( is_singular() ) : ?>
        <script>
        (function($) {
            $(document).on('facetwp-refresh', function() {
                FWP_HTTP.post_id = <?php echo get_the_ID(); ?>
            });
        })(jQuery);
        </script>
    <?php endif;
}, 100 );

/** access post_id in query args of facetwp template settings
 ** if using a visual query you'll first need to conver that to 
 ** advanced query args **/
add_filter( 'facetwp_query_args', function( $query_args, $class ) {
    if ( 'my_template_name' == $class->ajax_params['template'] ) {
        $post_id = isset( $class->http_params['post_id'] ) ? $class->http_params['post_id'] : get_the_id();
        // OR use if that doesn't work as expected - FWP()->facet->http_params['get'][ $post_id ]
    }
    return $query_args;
}, 10, 2 );
2 years ago
<?php

// See https://facetwp.com/how-to-use-hooks/
add_action( 'wp_head', function() {
?>
<script>
(function($) {
    $(document).on('facetwp-refresh', function() {
        FWP_HTTP.term_id = '<?php echo get_queried_object_id(); ?>';
    });
})(jQuery);
</script>
<?php
}, 100 );


// To access it (within your Query Arguments box)
$term_id = (int) $this->http_params['term_id'];