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 | |
/** 'author' is Unique name set in advanced tab of layout builder settings for the item, | |
** loop over the array returned from ACF to build a html string from the subfields and return to layout builder's | |
** facetwp_builder_item_value filter | |
**/ | |
add_filter( 'facetwp_builder_item_value', function( $value, $item ) { | |
if ( 'author' == $item['settings']['name'] ) { | |
$value = ''; | |
$authors = get_field( 'author' ); |
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
Radio button facets are actual divs rather than radio input type html. | |
Radio facet as rectangular buttons - https://d.pr/i/cnyjEg | |
Facet settings for demo - https://d.pr/i/C5lAsc | |
If you want to add an "All" button - https://gist.github.com/djrmom/5870f7baf38fd5df40ee861bb95a01d5 |
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
<?php | |
return array( | |
'post_type' => 'product', | |
'meta_query' => array( | |
array( | |
'key' => '_wc_booking_availability', | |
'compare' => 'EXISTS' | |
) | |
) | |
); |
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 | |
/** removes () from count, could also be used to replace with alternate bracketing or other output **/ | |
add_filter( 'facetwp_facet_html', function( $output, $params ) { | |
if ( 'product_categories' == $params['facet']['name'] ) { | |
$output = preg_replace( '/\(([0-9]+)\)/', '$1', $output ); | |
} | |
return $output; | |
}, 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 | |
/** scoll on loaded only if pager is the change in facet **/ | |
add_action( 'wp_head', function() { ?> | |
<script> | |
(function($) { | |
$(document).on('facetwp-refresh', function() { | |
if ( FWP.soft_refresh == true ) { | |
FWP.enable_scroll = true; |
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 | |
/** reset a facet (facet 2) on submission of different facet (facet 1) | |
** change 'search' to name of facet 1 | |
** change 'product_categories' to the name of the facet 2 | |
**/ | |
add_action( 'wp_footer', function() { | |
?> | |
<script> | |
(function($) { |
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 | |
/** index only first level children terms, no grandchildren or deeper **/ | |
add_filter( 'facetwp_index_row', function( $params ) { | |
if ( 'product_categories' == $params['facet_name'] ) { //change 'product_categories' to name of your facet | |
$parents = get_ancestors( $params['term_id'], 'product_cat', 'taxonomy' ); // change 'product_cat' to name of your taxonomy | |
if ( count( $parents ) !== 1 ) { // adjust comparison as needed for different child levels | |
$params['facet_value'] = ''; // skip indexing | |
} | |
} | |
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 | |
/** some types of product attributes for woocommerce (those that are not taxonomies or used for variations | |
** are saved only in the _product_attributes custom field as an array | |
** select "_product_attributes" as the datasource in the facet and use facetwp_index_row to find and index | |
** the correct attributes | |
**/ | |
add_filter( 'facetwp_index_row', function( $params, $class ) { | |
if ( 'attributes' == $params['facet_name'] ) { //change 'attributes' to name of your facet | |
$values = maybe_unserialize( $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
<?php | |
/** order by facet value (value shown in url on selection) instead of display value (label) **/ | |
add_filter( 'facetwp_facet_orderby', function( $orderby, $facet ) { | |
if ( 'day_of_week' == $facet['name'] ) { | |
$orderby = 'FIELD(f.facet_value, "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday")'; | |
} | |
return $orderby; | |
}, 10, 2 ); |
NewerOlder