Skip to content

Instantly share code, notes, and snippets.

@mgibbs189
mgibbs189 / functions.php
Last active December 29, 2020 14:07
FacetWP - pull in comment data
<?php
add_filter( 'facetwp_indexer_row_data', function( $rows, $params ) {
/* index the comment ratings */
if ( 'comment_rating' == $params['facet']['source'] ) {
$post_id = (int) $params['defaults']['post_id'];
$comments = get_comments( [ 'post_id' => $post_id ] );
foreach ( $comments as $comment ) {
$new_row = $params['defaults'];
@mgibbs189
mgibbs189 / functions.php
Created December 28, 2020 15:45
FacetWP - trigger Envira Gallery on ajax refresh
<?php
// Add to your (child) theme's functions.php
add_action( 'wp_head', function() {
?>
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
$(document).trigger('envira_load');
@mgibbs189
mgibbs189 / test.js
Created December 3, 2020 18:54
FacetWP - highlight template text containing search term
(function($) {
FWP.hooks.addAction('facetwp/loaded', function() {
var facet_name = 'search'; // EDIT ME
var allowed_elements = '.cat-item__title a, .cat-item__descr p'; // EDIT ME
var keywords = FWP.facets[facet_name].toString();
if ('' !== keywords) {
$(allowed_elements).each(function() {
var results = $(this).html();
@mgibbs189
mgibbs189 / functions.php
Created December 2, 2020 14:13
FacetWP - force get_the_post_thumbnail() to include a title tag
<?php
// Add to your (child) theme's functions.php
add_filter( 'wp_get_attachment_image_attributes', function( $attr, $attachment ) {
if ( ! isset( $attr['title'] ) ) {
$title = get_the_title( $attachment->ID );
if ( ! empty( $title ) ) {
$attr['title'] = $title;
jQuery(document).ready(function($) {
//* FacetWP Isotope
var fwpScrollToBtn = false;
var $grid = $('.fwpl-layout');
$grid.imagesLoaded(function() {
//* Wrapped in a short timeout function because $grid.imagesLoaded doesn't reliably lay out correctly
setTimeout(function(){
$grid.isotope({
itemSelector: '.fwpl-result',
});
<?php
// Add the following to your (child) theme's functions.php file
add_action( 'wp_head', function() {
?>
<script>
(function($) {
$(function() {
if ('undefined' !== typeof FWP) {
@mgibbs189
mgibbs189 / functions.php
Last active November 23, 2020 13:46
Enfold - fix product quantity buttons on refresh
<?php
// Add to your (child) theme's functions.php
add_action( 'wp_head', function() {
?>
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
$(document).trigger('updated_cart_totals'); // fix the "+/-" quantity buttons
<?php
// Add to your (child) theme's functions.php
add_filter( 'term_link', function( $termlink, $term, $taxonomy ) {
if ( 'portfolio_skills' == $taxonomy ) { /* TODO: this taxonomy name may need to change? */
$termlink = '/wineries-2/?_wine_types=' . $term->slug;
}
return $termlink;
}, 10, 3);
@mgibbs189
mgibbs189 / functions.php
Created November 12, 2020 16:15
Automatically expand all top-level terms
<?php
// Add to your (child) theme's functions.php file
add_action( 'wp_head', function() {
?>
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
$('.facetwp-facet-product_categories > .facetwp-checkbox .facetwp-expand').each(function() {
<?php
// Add the following into your (child) theme's functions.php
add_action( 'wp_head', function() {
?>
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
$('.fwpl-item.titleemail a').each(function() {