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 | |
/** | |
** requires at least 3.0.4 | |
**/ | |
add_filter( 'facetwp_query_args', function( $query_args, $class ) { | |
if ( 'posts_template' == $class->ajax_params['template'] && empty( $class->facets ) && $class->is_preload ) { | |
$query_args['posts_per_page'] = 1; | |
} | |
return $query_args; | |
}, 10, 2 ); |
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 | |
/** preload facet for specific page **/ | |
add_filter( 'facetwp_preload_url_vars', function( $url_vars ) { | |
if ( 'my_page' == FWP()->helper->get_uri() ) { | |
if ( empty( $url_vars ) ) { // or check a specific facet empty( $url_vars['some_facet'] ) | |
$value = 'something' // 'something' should be looked up for 'my_page' | |
$url_vars['some_facet'] = array( $value ); | |
} | |
} | |
return $url_vars; |
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 | |
/** to use this make sure all queries to be used | |
** for facets have 'facetwp' => true in query args, including the | |
** query args setting in a facetwp template | |
**/ | |
// add 'facetwp' => false anytime it is not already set | |
add_action( 'pre_get_posts', function( $query ) { | |
if ( ! isset( $query->query_var['facetwp'] ) ) { | |
$query->set( 'facetwp', false ); |
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
<div id="fwpm-infobox"> | |
<h1 class="fwpm-infobox-title"><?php the_title(); ?></h1> | |
<div class="fwpm-infobox-content"><?php the_excerpt(); ?></div> | |
</div> |
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
(function($) { | |
$(document).on('change', '.facetwp-facet-product_categories', function() { // change product_categories to name of dropdown facet | |
FWP.is_reset = true; | |
FWP.facets['product_tags'] = []; // set other facet to no selections | |
delete FWP.facets['paged']; // remove "paged" from URL | |
FWP.refresh(); | |
}); | |
$(document).on('change', '.facetwp-facet-product_tags', function() { // change product_tags to name of dropdown facet | |
FWP.is_reset = true; | |
FWP.facets['product_categories'] = []; // set other facet to no selections |
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 | |
add_filter( 'facetwp_preload_url_vars', function( $url_vars ) { | |
if ( 'demo/cars' == FWP()->helper->get_uri() ) { | |
if ( empty( $url_vars['make'] ) && empty( $url_vars['other_facet'] ) ) { | |
$url_vars['make'] = array( 'audi' ); | |
$url_vars['other_facet'] = array( 'something' ); | |
} | |
} elseif ( 'demo/otherpage' == FWP()->helper->get_uri() ) { | |
if ( empty( $url_vars['make'] ) && empty( $url_vars['other_facet'] ) ) { |
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 | |
// re-index your facets after adding this code | |
add_filter( 'facetwp_index_row', function( $params, $class ) { | |
if ( 'author' == $params['facet_name'] ) { | |
$user = get_user_by( 'id', $params['facet_value'] ); | |
if ( false !== $user ) { | |
$params['facet_display_value'] = $user->last_name . ', ' . $user->first_name | |
} | |
} | |
return $params; |
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 | |
/** | |
* reindex after adding or updating this filter | |
*/ | |
add_filter( 'facetwp_index_row', function( $params, $class ) { | |
if ( 'date_as_year' == $params['facet_name'] ) { // change date_as_year to name of your facet | |
$raw_value = $params['facet_value']; | |
$params['facet_value'] = date( 'Y', strtotime( $raw_value ) ); | |
$params['facet_display_value'] = $params['facet_value']; |
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
$(document).on('facetwp-loaded', function() { | |
$('.facetwp-facet').each(function() { | |
var facet_name = $(this).attr('data-name'); | |
var facet_label = FWP.settings.labels[facet_name]; | |
if ( 'undefined' !== typeof FWP.settings.num_choices[facet_name] && FWP.settings.num_choices[facet_name] > 0 && $('.facet-label[data-for="' + facet_name + '"]').length < 1 ) { | |
$(this).before('<h3 class="facet-label" data-for="' + facet_name + '">' + facet_label + '</h3>'); | |
} | |
}); | |
}); |
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 | |
/** | |
* attaches a click even to a div that selects all of a checkbox facets available options and triggers a refresh | |
* change "product_categories" to the name of your facet | |
* <div class="facetwp-checkbox select-all">Select all</div> creates a div that looks like facet checkboxes | |
* | |
*/ | |
add_action( 'wp_head', function() { ?> | |
<script> |