Skip to content

Instantly share code, notes, and snippets.

@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 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 / custom-hooks.php
Created October 17, 2019 18:14
facetwp schedule indexer
<?php
/** needs to be availble to cron to run **/
function fwp_single_index( $id ) {
FWP()->indexer->index( $id );
}
add_action( 'fwp_single_index', 'fwp_single_index' );
/** place in whatever function you want to initiate indexing, ex. after running an import **/
wp_schedule_single_event( time(), 'fwp_single_index', array( $post_id ) );
@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 / 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 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 / facet.html
Last active January 24, 2021 08:20
facetwp reset button in elementor
<!--
Add elmentor button widget
Use link to #
Set class in advanced to .facetwp-reset-btn https://d.pr/i/b05YIM
Add following js, it can be added in an elementor html code widget (https://d.pr/i/Lat8Z4)
if you don't have a theme/plugin setting or custom code you are using
-->
<script>
(function($) {
$(document).on('click', '.facetwp-reset-btn', function(e) {
@djrmom
djrmom / custom-hooks.php
Created May 20, 2020 19:10
facetwp elementor cards elementor-has-item-raio class
<?php
/** re-adds elementor-has-item-radio afer refresh **/
add_action( 'wp_head', function() { ?>
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
$('.facetwp-template .elementor-posts-container').addClass('elementor-has-item-ratio');
});
})(jQuery);
</script>