Created
January 8, 2018 17:47
-
-
Save anonymous/e091b253b57a328dfb65746a48bfdb84 to your computer and use it in GitHub Desktop.
Attempt to preload the days events using a specific link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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