Skip to content

Instantly share code, notes, and snippets.

@mgibbs189
mgibbs189 / gist:6e575a89c75628d2893f
Last active October 11, 2018 12:44
FacetWP support for Packery (Masonry-like JS layouts)
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
$('.blog-grid').packery({
itemSelector: '.blog-item'
});
});
})(jQuery);
</script>
@mgibbs189
mgibbs189 / gist:277cdd9f615987247e15
Last active October 11, 2018 12:38
Mediaelement AJAX fix
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
if (FWP.loaded) {
$('.wp-audio-shortcode, .wp-video-shortcode').mediaelementplayer();
}
});
})(jQuery);
</script>
@mgibbs189
mgibbs189 / gist:9ff66c05cc9c60a235a3
Created September 26, 2014 13:05
FacetWP + Co-Authors Plus
<?php
$args = array(
'posts_per_page' => -1,
'post_type' => 'bookshelf',
'post_status' => 'publish',
'tax_query' => array( // Query on the "Co-Authors Plus" custom taxonomy
array(
'taxonomy' => 'author',
'terms' => $author // the author ID
@mgibbs189
mgibbs189 / gist:e96b8a4b70f810ce6b73
Last active October 11, 2018 12:44
FacetWP - set default slider "start" values
<?php
function my_facetwp_render_output( $output, $params ) {
$facet_name = 'YOUR_FACET_NAME'; // CHANGE ME
foreach ( $params['facets'] as $facet ) {
if ( $facet_name == $facet['facet_name'] && empty( $facet['selected_values'] ) ) {
$output['settings'][ $facet_name ]['start'] = array( 10, 50 );
}
}
@mgibbs189
mgibbs189 / gist:6c53e5ee5b4d00839877
Last active October 11, 2018 12:46
Index the related product price for Tribe events
<?php
function index_event_cost( $params, $class ) {
if ( 'evenementen_prijs' == $params['facet_name'] ) {
if ( function_exists( 'tribe_get_cost' ) ) {
$cost = tribe_get_cost( $params['post_id'], false );
$params['facet_value'] = $cost;
$params['facet_display_value'] = $cost;
}
}
@mgibbs189
mgibbs189 / gist:6567111f7a2551090c8d
Last active October 11, 2018 12:46
Content fade in / fade out
<script>
(function($) {
$(document).on('facetwp-refresh', function() {
$('.facetwp-template').animate({ opacity: 0 }, 1000);
});
$(document).on('facetwp-loaded', function() {
$('.facetwp-template').animate({ opacity: 1 }, 1000);
});
})(jQuery);
</script>
@mgibbs189
mgibbs189 / gist:d92ebcaeb0aade38859a
Last active October 11, 2018 12:48
Filter results to children post items (Types plugin)
<?php
/**
* Context:
* Using the Types plugin, the "Resources" post type is a child of the "Courses" post type.
* On a Course page, show only Resources belonging to the current Course
*
* _wpcf_belongs_courses_id
* This custom field stores the ID of a Resource's parent Course
*/
@mgibbs189
mgibbs189 / test.php
Created July 21, 2015 19:57
FacetWP - custom slider step sizes
<?php
function custom_slider_steps( $output, $params ) {
$output['settings']['YOUR_SLIDER_FACET_NAME']['range'] = array(
'min' => array( 0.001 ),
'25%' => array( 0.01, 0.01 ),
'50%' => array( 1, 1 ),
'75%' => array( 100, 100 ),
'max' => array( 250000 )
);
@mgibbs189
mgibbs189 / test.php
Last active October 3, 2017 12:14
FacetWP - remove 200 post limit from SearchWP 2.6+
<?php
add_filter( 'searchwp_swp_query_args', function( $args ) {
if ( isset( $args['facetwp'] ) ) {
$args['posts_per_page'] = -1;
}
return $args;
} );
@mgibbs189
mgibbs189 / test.js
Last active January 3, 2023 16:59
FacetWP - available facet settings
/* updated 2019-02-22 */
{
"facets": [
{
"name": "test_checkboxes",
"label": "Test checkboxes",
"type": "checkboxes",
"source": "post_type",
"parent_term": "",
"hierarchical": "no",