Skip to content

Instantly share code, notes, and snippets.

@adaptifyDesigns
Created April 20, 2016 16:36
Show Gist options
  • Save adaptifyDesigns/18d7acb2e62c27f406ca0f2068d6b857 to your computer and use it in GitHub Desktop.
Save adaptifyDesigns/18d7acb2e62c27f406ca0f2068d6b857 to your computer and use it in GitHub Desktop.
FacetWP Autocomplete facet with custom post type query (template).
<?php
///////////////////////////////////////////
// Movement Library:
//////////////////////////////////////////
// Facets:
echo facetwp_display( 'facet', 'post_title_autocomplete_search' );
// The Loop
if ( have_posts() ) {
?>
<div class="resources--movement-library-section">
<h2 class="resources--section-headline">Movement Library</h2>
<p>
This library will continue to grow as we add new videos and recieve new requests from you all. So please contact us (in the "Help Me!" tab to your left) with any questions about movements.
</p>
<div id="member-resources-movements" style="font-size: 14px;">
<div class="resources--movement-library-intro-video">
<?php
// echo do_shortcode('
// [button type="transparent" id="movement_intro_video" class="video-link-button" lightbox_video="true" link="true" href="https://www.youtube.com/embed/CR3BHnDJAWA/?autoplay=1&rel=0"]Movement Library Introduction[/button]
// [lightbox selector="#movement_intro_video"]
// ');
?>
</div>
<ul class="x-block-grid three-up facetwp-template">
<?php
$movement_counter = 1;
while ( have_posts() ) {
the_post();
global $post;
$movement_title = $post->post_title;
$movement_slug = $post->post_name;
$youtube_id = get_field('movement_yt_id');
?>
<li class="resources--movement-library_movement x-block-grid-item">
<?php
echo do_shortcode('
[image id="movement_' . $movement_slug . '_' . $youtube_id .'" src="https://img.youtube.com/vi/' . $youtube_id .'/mqdefault.jpg" alt="'. $movement_title .'" type="thumbnail" lightbox_video="true" link="true" href="https://www.youtube.com/embed/' . $youtube_id .'/?autoplay=1&rel=0"]
'. $movement_title .'
[lightbox selector="#movement_' . $movement_slug . '_' . $youtube_id .'"]
');
?>
</li>
<?php
$movement_counter++;
}
?>
</ul>
</div>
</div>
<?php
} else {
echo '<p>Darn... sorry the Movement Library is not currently available. Please <a href="">contact us</a> and let us know so we can fix it asap.</p>';
}
?>
<script>
(function($) {
// Infinite Scroll for faceted loop:
// Source: https://facetwp.com/infinite-scroll-with-facetwp/
window.fwp_is_paging = false;
$(document).on('facetwp-refresh', function() {
if (! window.fwp_is_paging) {
window.fwp_page = 1;
FWP.extras.per_page = 'default';
}
window.fwp_is_paging = false;
});
$(document).on('facetwp-loaded', function() {
window.fwp_total_rows = FWP.settings.pager.total_rows;
if (! FWP.loaded) {
window.fwp_default_per_page = FWP.settings.pager.per_page;
$(window).scroll(function() {
if ($(window).scrollTop() == $(document).height() - $(window).height()) {
var rows_loaded = (window.fwp_page * window.fwp_default_per_page);
if (rows_loaded < window.fwp_total_rows) {
window.fwp_page++;
window.fwp_is_paging = true;
FWP.extras.per_page = (window.fwp_page * window.fwp_default_per_page);
FWP.soft_refresh = true;
FWP.refresh();
}
}
});
}
});
})(jQuery);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment