Skip to content

Instantly share code, notes, and snippets.

@djrmom
djrmom / custom-hooks.php
Last active September 26, 2020 15:15
facetwp only products
<?php
/* only filter product queries */
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( 'product_query' != $query->get( 'wc_query' ) ) {
$is_main_query = false;
}
return $is_main_query;
}, 10, 2 );
@djrmom
djrmom / custom-hooks.php
Created January 9, 2018 21:06
facetwp index taxonomy name instead of slug
/**
* reindex after adding or updating this filter
*/
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'my_facet' == $params['facet_name'] ) { // change my_facet to name of your facet
$params['facet_value'] = $params['facet_display_value'];
}
return $params;
}, 10, 2 );
@djrmom
djrmom / custom-hooks.php
Last active April 19, 2018 15:28
facetwp wp job manager
<?php
// add currentcy to rate
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'my_facet_name' == $params['facet_name'] ) { // change 'my_facet_name' to name of your facet
$currency = get_custom_field( 'name_of_field', $params['post_id'] ); // change 'name_of_field' to your field name to look up the currency field by $params['post_id'];
$params['facet_display_value'] = $params['facet_display_value'] . ' ' . $currency;
}
return $params;
}, 10, 2 );
@djrmom
djrmom / pagination-old.php
Last active June 9, 2021 13:22
facetwp woocommerce pagination
<?php
/**
* Pagination - Show numbered pagination for catalog pages
*
* This template can be overridden by copying it to yourtheme/woocommerce/loop/pagination.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
@djrmom
djrmom / custom-hooks.php
Last active August 24, 2020 17:44
facetwp index only parents
<?php
/*
Plugin Name: Custom Hooks
Plugin URI: https://facetwp.com/
Description: A container for custom hooks
Version: 1.0
Author: FacetWP, LLC
*/
add_filter( 'facetwp_index_row', function( $params, $class ) {
@djrmom
djrmom / facetwp.php
Last active April 19, 2018 15:24
facetwp listable html filter
<?php
/*
* Filter the html of each facet and add labels in front
*/
function listable_facetwp_facet_html( $html, $params ) {
if ( isset( $params['facet'] ) && isset( $params['facet']['label'] ) ) {
$html = '<label class="facetwp-filter-title">' . facetwp_i18n( $params['facet']['label'] ) . '</label><div class="facet-wrapper">' . $html . '</div>';
}
@djrmom
djrmom / custom-hooks.php
Created January 19, 2018 19:55
facetwp meta query order by field
<?php
$args = array(
'level' = > array(
'key' => '_hmd_practice_membership_level',
'value' => array( 'gold', 'silver', 'bronze', 'basic', 'free' ),
'compare' => 'IN'
)
);
@djrmom
djrmom / custom-hooks.php
Created January 23, 2018 16:13
facetwp check post type query
<?php
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( 'event' !== $query->get( 'post_type' ) ) {
$is_main_query = false;
}
return $is_main_query;
}, 10, 2 );
@djrmom
djrmom / cars.html
Last active April 11, 2018 13:09
facetwp cars demo
<style>
.facetwp-facet.facetwp-facet-vehicle_type {
margin-bottom: 0;
}
.facetwp-facet-vehicle_type .facetwp-radio {
display: inline-block;
background: none;
line-height: 48px;
width: 120px;
margin: 0;
@djrmom
djrmom / custom-hooks.php
Last active August 24, 2020 17:44
facetwp index category and its children
<?php
/** reindex after adding filter code */
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'label_fr' == $params['facet_name'] ) { // change if needed
if ( 183 != $params['term_id'] && 183 != $params['parent_id'] ) ) {
$params['facet_value'] = '';
}
}