Skip to content

Instantly share code, notes, and snippets.

@djrmom
djrmom / custom-hooks.php
Created December 18, 2020 16:57
facetwp ignore query by posts_per_page
<?php
// Add to your (child) theme's functions.php
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( 2 > $query->get( 'posts_per_page', 0 ) ) {
$is_main_query = false;
}
return $is_main_query;
}, 10, 2 );
@djrmom
djrmom / custom-hooks.php
Last active December 16, 2020 17:53
facetwp scrollTop example with wp_head hook
<?php
/** adds script to header
** https://facetwp.com/how-to-add-pagination-scrolling/
**/
add_action( 'wp_head', function() { ?>
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
if (FWP.loaded) {
$('html, body').animate({
@djrmom
djrmom / custom-hooks.php
Last active February 17, 2021 02:26
facetwp elementor facetwp false with query id
<?php
/** if facet is identifying the wrong query in elementor
** add a custom query id 'block_facet' to your query settings in the element
** to NOT have facet identify as the main query
** https://developers.elementor.com/custom-query-filter/
**/
add_action( 'elementor/query/block_facet', function( $query ) {
$query->set( 'facetwp', false );
} );
@djrmom
djrmom / custom-hooks.php
Created November 3, 2020 19:47
facetwp close flyout on facetwp-loaded
<?php
/** close flyout on facetwp-loaded so that the user doesn't need to close after facet refreshes **/
add_action( 'wp_head', function() { ?>
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
if (FWP.loaded && $('.facetwp-flyout').hasClass('active') ) {
FWP.flyout.close();
}
});
@djrmom
djrmom / custom-hooks.php
Created October 28, 2020 17:47
facetwp fit_bounds
add_action( 'wp_head', function() {
?>
<script>
(function($) {
$(function() {
if ( 'undefined' !== typeof FWP && 'undefined' !== typeof FWP.hooks) {
FWP.hooks.addFilter('facetwp_map/fit_bounds', function( fit_bounds ) {
if ( FWP.loaded ) {
return fit_bounds;
} else {
@djrmom
djrmom / facetwp-schedule-indexer.php
Last active January 26, 2021 16:56
facetwp schedule indexer
<?php
/*
Plugin Name: FacetWP Schedule Indexer
Plugin URI: https://facetwp.com/
Description: Runs indexer periodically by cron
Version: 1.0
Author: FacetWP, LLC
*/
add_action( 'fwp_scheduled_index', 'fwp_scheduled_index' );
@djrmom
djrmom / custom-hooks.php
Created October 16, 2020 18:52
facetwp fselect label
/**
* Use a default label in the open fselect dropdown different from the default shown when closed
* change facetwp-facet-product_categories to name of your facet and Custom Label to the label you want to use
**/
add_action( 'wp_head', function() { ?>
<script>
(function($) {
$(function() {
if ('object' !== typeof FWP) {
return;
@djrmom
djrmom / custom-hooks.php
Created September 28, 2020 18:13
facetwp use term as css class in layout builder
<?php
/** creates a space seperated list of terms (instead of links) for use in
** dynamic tags for outputting a css class
**/
add_action( 'facetwp_builder_item_value', function( $value, $item ) {
if ( 'product-categories' == $item['settings']['name'] ) {
$value = "";
$terms = wp_get_post_terms( get_the_ID(), 'product_cat' );
if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) {
foreach ( $terms AS $term ) {
@djrmom
djrmom / custom-hooks.php
Created September 14, 2020 17:25
facetwp don't load facetwp conditional assets
<?
/**
** keeps facetwp conditional's frontend assets from loading
**/
add_action( 'wp_footer', function() {
wp_dequeue_style( 'fwpcl-front' );
wp_dequeue_script( 'fwpcl-front' );
}, 11 );
@djrmom
djrmom / custom-hooks.php
Created September 14, 2020 13:45
facetwp always ignore archive query
<?php
/** always ignore archive query as main query for facet **/
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( $query->is_archive() && $query->is_main_query() ) {
$is_main_query = false;
}
return $is_main_query;
}, 10, 2 );