Skip to content

Instantly share code, notes, and snippets.

@stevesearer
Last active October 3, 2017 21:09
Show Gist options
  • Save stevesearer/e8509b6a4b6b19aceee0349e4c6f1160 to your computer and use it in GitHub Desktop.
Save stevesearer/e8509b6a4b6b19aceee0349e4c6f1160 to your computer and use it in GitHub Desktop.
<?php
function fwp_preload_facets() {
?>
<script>
(function($) {
$(document).on('facetwp-refresh', function() {
if (! FWP.loaded && '' == FWP.build_query_string()) {
FWP_HTTP.post_id = '<?php global $post; ?><?php echo $post->ID; ?>';
FWP.facets['product_availability'] = ['americas'];
}
});
})(jQuery);
</script>
<?php
}
add_action( 'wp_head', 'fwp_preload_facets', 100 );
add_filter( 'facetwp_template_force_load', '__return_true' );
// My Template Query Arguments
$post_id = (int)(isset($this->http_params['post_id']) ? $this->http_params['post_id'] : null);
return array(
'post_type' => 'products',
'posts_per_page' => -1,
'post_status' => 'publish',
'order' => 'ASC',
'orderby' => 'title',
'meta_query' => array(
array(
'key' => 'product_parent_id',
'compare' => '=',
'type' => 'numberic',
'value' => $post_id,
)
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment