Skip to content

Instantly share code, notes, and snippets.

@djrmom
djrmom / custom-hooks.php
Created September 10, 2020 21:54
facetwp force template query
<?php
/** add 'facetwp' => true to *ALL* facetwp template query args **/
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( true !== $query->get( 'facetwp', false ) ) {
return false;
}
return $is_main_query;
}, 10, 2 );
@djrmom
djrmom / facetwp.js
Created September 8, 2020 15:14
facetwp flatsome equal heights
/** for using flatsome equal heights setting
** see https://facetwp.com/how-to-use-hooks/#hooks-link for how to add this js
** in a snippets plugin or functions.php
**/
(function($) {
$(document).on('facetwp-loaded', function() {
Flatsome.attach("equalize-box", $(".facetwp-template"));
});
})(jQuery);
@djrmom
djrmom / custom-hooks.php
Last active September 29, 2020 13:33
facetwp wpml indexing
<?php
/** fix for second lang being deleted on post index */
add_filter( 'facetwp_indexer_query_args', function( $args ) {
if ( function_exists( 'is_checkout' ) && is_checkout() ) {
return $args;
}
do_action( 'wpml_switch_language', 'all' );
@djrmom
djrmom / custom-hooks.php
Created August 20, 2020 18:36
facetwp woocommerce 4.4.0 pagination fix
<?php
/** fix for woocommerce pagination not updated during facet refresh **/
add_action( 'pre_get_posts', function( $query ) {
if ( true === $query->get( 'facetwp' ) && 'product_query' == $query->get( 'wc_query' ) ) {
$prefix = FWP()->helper->get_setting( 'prefix' );
$name = $prefix . 'paged';
// Set the paged var
if ( isset( FWP()->facet->http_params['get'][ $name ] ) ) {
set_query_var( 'paged', (int) FWP()->facet->http_params['get'][ $name ] );
@djrmom
djrmom / custom-hooks.php
Created August 20, 2020 14:53
facetwp ignore sticky posts in blog archive
<?php add_filter( 'pre_get_posts', function( $query ) {
if ( $query->is_main_query() && is_home() ) {
$query->set( 'ignore_sticky_posts', true );
}
});
@djrmom
djrmom / custom-hooks.php
Created August 4, 2020 14:48
facetwp layout builder shortcodes
<?php
/** use do_shortcode on all layout builder items
** it is preferrable to target specific items
** as in https://facetwp.com/documentation/developers/output/facetwp_builder_item_value/
** if possible
**/
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
$value = do_shortcode( $value );
return $value;
@djrmom
djrmom / map.css
Created July 30, 2020 12:41
facetwp map facet css
/** hide enable filtering button **/
.facetwp-map-filtering {
display: none;
}
/** hides map markers **/
.gm-style > div:first-of-type > div:first-of-type > div > div:nth-of-type(2) {
display: none;
}
@djrmom
djrmom / custom-hooks.php
Last active August 24, 2020 17:48
facetwp create custom range dropdown
<?php
/** custom index to display a dropdown facet as a range
** change 'CHANGE_ME' to the name of your facet
** facet settings should be a dropdown type and the datasourc
** of the value you want to show as a range **/
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'CHANGE_ME' == $params['facet_name'] ) {
$price = $params['facet_value'];
@djrmom
djrmom / facet.css
Created July 29, 2020 13:39
facetwp hide map markers with css
/** hides map markers on facetwp map facet with css **/
.gm-style > div:first-of-type > div:first-of-type > div > div:nth-of-type(2) {
display: none;
}
@djrmom
djrmom / custom-hooks.php
Last active August 24, 2020 17:48
facetwp copy range to dropdown
<?php
/** create a range list facet with the ranges you need
** create a dropdown facet with any datasource, post type is good its just a placeholder
** change the code below to match your facet names
**/
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'my_range_facet' == $params['facet_name'] ) { // change 'my_range_facet' to the name of your range list facet
$params['facet_name'] = 'dropdown_range'; // trick FacetWP into saving values into the other facet
} elseif ( 'dropdown_range' == $params['facet_name'] ) { // change 'dropdown_range' to the name of your dropdown facet in this and the above line