Skip to content

Instantly share code, notes, and snippets.

@djrmom
djrmom / custom-hooks.php
Created February 8, 2021 14:56
facetwp GDPR Cookie Consent compatiblity
<?php
/** ignore query added by GDPR Cookie Consent **/
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( 'cookielawinfo' == $query->get( 'post_type' ) ) {
$is_main_query = false;
}
return $is_main_query;
}, 10, 2 );
@djrmom
djrmom / query.php
Created February 5, 2021 18:54
facetwp woocommerce product visibility
// example for product visibility for woocommerce query
// hides out of stock
'tax_query' => array(
array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'outofstock',
'operator' => 'NOT IN',
),
@djrmom
djrmom / facet-display.php
Created January 29, 2021 22:34
facetwp product loop display code
<?php
if ( have_posts() ) {
do_action( 'woocommerce_before_shop_loop' );
woocommerce_product_loop_start();
while ( have_posts() ) {
the_post();
do_action( 'woocommerce_shop_loop' );
wc_get_template_part( 'content', 'product' );
}
woocommerce_product_loop_end();
@djrmom
djrmom / custom-hooks.php
Created January 26, 2021 19:16
facetwp redirect on refresh
<?php
/** adds script to header
**/
add_action( 'wp_head', function() { ?>
<script>
(function($) {
$(document).on('facetwp-refresh', function() {
if (FWP.loaded && 'recipes' != FWP_HTTP.uri) { // if not the initial pageload, and we're on the homepage
window.location.href = '/recipes/?' + FWP.build_query_string(); // redirect
@djrmom
djrmom / custom-hooks.php
Created January 25, 2021 23:17
facetwp make result in layout builder clickable
/**
** adds click even to each facetwp layout builder result to trigger
** a click on the first link within the result
**/
add_action( 'wp_footer', function() {
?>
<script>
(function($) {
$( '.facetwp-template' ).on( "click", ".fwpl-result", function() {
$(this).find('a:first')[0].click();
@djrmom
djrmom / custom-hooks.php
Created January 22, 2021 23:02
facetwp show hide template based on facets selected
add_action( 'wp_head', function() {
?>
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
if ('' != FWP.build_query_string()) {
$('.facetwp-template').show();
} else {
$('.facetwp-template').hide();
}
@djrmom
djrmom / custom-hooks.php
Created January 20, 2021 19:57
facetwp yoast seo filter robots
<?php
/** basic check to modify robots when facets are selected during pre-load **/
add_filter( 'wpseo_robots_array', function( $robots, $class ) {
if ( function_exists( 'FWP' ) && !empty( FWP()->ajax->url_vars ) ) {
$robots['index'] = 'noindex';
$robots['follow'] = 'nofollow';
}
return $robots;
}, 10, 2);
@djrmom
djrmom / products.php
Last active January 19, 2021 19:26
facetwp bigcommerce shortcode
<?php
/**
* Product Group Template for Bigcommerce modified for FacetWP
* add to your_theme/bigcommerce/components/products/product-shortcode-grid.php
* @var string[] $cards
* @var string $pagination
* @var bool $wrap Whether to wrap the output in a div
* @var int $columns The number of columns to use for the grid
* @version 1.0.0
*/
@djrmom
djrmom / custom-hooks.php
Last active December 28, 2020 18:04
facetwp custom image size for ACF image field in layout builder
<?php
/**
** for creating custom image sizes
** https://developer.wordpress.org/reference/functions/add_image_size/
**/
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
if ( 'my-image' == $item['settings']['name'] && !empty( $value ) ) { // change 'my-image' to the unique name of your field
$image = get_field('acf_image_field'); // change 'acf_image_field' to the name of your acf field
if ( $image ) $value = wp_get_attachment_image( $image, 'thumbnail' ); // 'thumbnail' can be changed to other image sizes you have available
}
@djrmom
djrmom / facet.css
Created December 22, 2020 16:45
facetwp css for rtl flyout
.rtl .facetwp-flyout {
transform: translateX(100%);
}