1 week ago
<?php
// output only sub categories of current woocommerce product category
add_filter( 'facetwp_facet_render_args', function( $args ) {
if ( 'my_facet_name' == $args['facet']['name'] && is_product_category() ) { // replace 'my_facet_name' with the name of your facet
$current_term = get_queried_object_id();
foreach ( $args['values'] as $key => $row ) {
/* to also include current term in chocies add this to if:
&& $row['term_id'] != $current_term
*/
if ( $row['parent_id'] != $current_term ) {
unset( $args['values'][$key] );
}
}
$args['values'] = array_values( $args['values'] ); // fixes indexes
}
return $args;
});
3 weeks ago
<?php
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'my_facet_name' == $params[ 'facet_name' ] ) { // replace 'my_facet_name' with name of facet to index with hierarchy
if ( 0 === strpos( $params['facet_source'], 'cf/attribute_pa_' ) ) {
$taxonomy = str_replace( 'cf/attribute_', '', $params['facet_source'] );
$term = get_term_by( 'slug', $params['facet_value'], $taxonomy );
if ( false !== $term ) {
$params['term_id'] = $term->term_id;
$params['parent_id'] = $term->parent;
$params['facet_display_value'] = $term->name;
$params['depth'] = count( get_ancestors( $term->term_id, $taxonomy, 'taxonomy' ) );
}
}
}
return $params;
}, 10, 2 );
3 weeks ago
<?php
/**
** including a facetwp shortcode in a block pattern
**/
if ( ! is_admin() && ! ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
echo do_shortcode('[facetwp facet="categories"]');
} else {
echo '<!-- wp:shortcode -->[facetwp facet="categories"]<!-- /wp:shortcode -->';
} ?>
1 month ago
<?php
/** fix incorrect post_ok=false in relevanssi **/
add_filter( 'facetwp_facet_filter_posts', function( $return ) {
// remove filter before running relevanssi search
remove_filter( 'post_password_required', 'rcp_post_password_required_rest_api', 10 );
return $return;
}, 1 );
1 month ago
<?php
// If you are using the Submit Button add-on and want the redirect not to happen when your facet is empty,
// use the following script and de-activate the add-on. This is basically the same as facetwp-submit.js, but with an
// extra check in L13-14 to check if a specific facet is empty when the Submit button is clicked. If it is, the redirect does not happen.
// This can be useful to prevent 'empty' redirects for facet types that refresh themselves, like an Autocomplete facet that submits on Enter or clicking a selection.
add_action( 'facetwp_scripts', function() {
?>
<script>
(function($) {
$().on('click', '.fwp-submit', function() {
FWP.parseFacets();
// Do nothing if this facet is empty
if ( ! FWP.facets['my_facet_name'].length ) { // Replace 'my_facet_name' with the name of your facet
return;
}
var href = $(this).attr('data-href');
var query_string = FWP.buildQueryString();
if (query_string.length) {
var prefix = (-1 < href.indexOf('?')) ? '&' : '?';
href += prefix + query_string;
}
window.location.href = href;
});
})(fUtil);
</script>
<?php
}, 100 );
1 month ago
<?php
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
if ( 'el-isuok7' == $item['settings']['name'] ) { // Replace 'el-isuok7' with the'Unique name' of your Listing Builder repeater item
$fieldvalues = get_field( 'automerkit' ); // Replace 'automerkit' with the name of your Repeater field
if( $fieldvalues ) {
$output = array_map(function($arr) {
return implode(', ', $arr);
}, array_map('array_values', $fieldvalues));
$value = implode(', ', $output);
}
}
return $value;
}, 10, 2 );
1 month ago
<?php
// Use readonly instead of disabled to for "Copy" Metabox fields in WPML
// See: https://facetwp.com/help-center/using-facetwp-with/meta-box/#fix-indexing-issues-when-using-meta-box-with-wpml
add_filter( 'rwmb_text_html', function( $html ) {
return str_replace( 'disabled', 'readonly', $html );
}, 10 );
2 months ago
<!--To be used in a Listing Builder listing in Dev mode-->
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ): the_post(); ?>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php endwhile; ?>
<!--Adds an extra post item (for example an ad) at the end of the query-->
<?php if ( $wp_query->max_num_pages == FWP()->facet->ajax_params['paged'] ) : ?>
<div>This is my extra post item<div>
<?php endif; ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
2 months ago
<style>
/**
** replace test_facet with name of your fselect
**/
.facetwp-facet-test_facet .fs-dropdown {
position: relative;
border: none;
}
.facetwp-facet-test_facet .fs-dropdown.fs-hidden {
display: block;
position: relative;
}
.facetwp-facet-test_facet .fs-dropdown .fs-search {
display: none;
}
.facetwp-facet-test_facet .fs-label-wrap {
display: none;
}
.facetwp-facet-test_facet .fs-dropdown .fs-options {
overflow: visible;
max-height: none
}
</style>
2 months ago
<?php
// Syncs the selected values of two facets with different types when using one of the facets.
// The facets need to use the same Data Source.
// Change 'categories_radio' and 'categories_dropdown' to the names of your facets.
// Caveat: both facets will ghost each other's choices. This may not be optimal/desired.
// This can be fixed with the second snippet. Until a Dropdown facet has ghosts, this is not (yet) possible for Dropdowns.
add_action( 'facetwp_scripts', function() {
?>
<script>
document.addEventListener('facetwp-refresh', function() {
if (null !== FWP.active_facet) {
if ( 'categories_radio' == fUtil(FWP.active_facet.nodes[0]).attr('data-name' ) ) {
FWP.facets['categories_dropdown'] = FWP.facets['categories_radio'];
} else if ( 'categories_dropdown' == fUtil(FWP.active_facet.nodes[0]).attr('data-name' ) ) {
FWP.facets['categories_radio'] = FWP.facets['categories_dropdown'];
}
}
});
</script>
<?php
}, 100 );
// Optional: remove unclickable ghosts from the Radio facet
add_filter( 'facetwp_facet_html', function( $output, $params ) {
if ( 'categories_radio' == $params['facet']['name'] ) {
$output = str_replace ( 'disabled' , '' , $output );
}
return $output;
}, 10, 2 );