Skip to content

Instantly share code, notes, and snippets.

Created January 8, 2018 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/e091b253b57a328dfb65746a48bfdb84 to your computer and use it in GitHub Desktop.
Save anonymous/e091b253b57a328dfb65746a48bfdb84 to your computer and use it in GitHub Desktop.
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() {
if( isset( $_GET['today'] ) ) :
?>
<style>
.facetwp-template #events {
visibility: hidden;
}
</style>
<script>
(function($) {
$(document).on('facetwp-refresh', function() {
if (! FWP.loaded && 'today=true' == FWP.build_query_string() && 'events' == FWP_HTTP.uri) {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10){
dd='0'+dd;
}
if(mm<10){
mm='0'+mm;
}
var today = yyyy + '-' + mm + '-' + dd;
FWP.facets['event_dates'] = [today];
}
});
$(document).on('facetwp-loaded', function() {
$( '.facetwp-template #events' ).css('visibility', 'visible');
});
})(jQuery);
</script>
<?php
endif;
}
add_action( 'wp_head', 'fwp_preload_facets', 100 );
add_filter( 'facetwp_template_force_load', '__return_true' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment