Skip to content

Instantly share code, notes, and snippets.

@mgibbs189
mgibbs189 / functions.php
Last active May 2, 2024 09:34
Flatsome - support lazy load images and quick view
<?php
add_action( 'wp_head', function() {
?>
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
Flatsome.behaviors['lazy-load-images'].attach();
Flatsome.behaviors['quick-view'].attach();
});
@mgibbs189
mgibbs189 / 01_Query_Arguments.php
Last active August 27, 2023 10:11
FacetWP - show both a Google Map and a result listings
<?php
return array(
"post_type" => "park",
"post_status" => "publish",
"posts_per_page" => 100
);
@mgibbs189
mgibbs189 / test.js
Last active January 3, 2023 16:59
FacetWP - available facet settings
/* updated 2019-02-22 */
{
"facets": [
{
"name": "test_checkboxes",
"label": "Test checkboxes",
"type": "checkboxes",
"source": "post_type",
"parent_term": "",
"hierarchical": "no",
@mgibbs189
mgibbs189 / functions.php
Last active October 26, 2022 14:02
FacetWP - index multiple dates from a single string
<?php
// here is the code you need
// input: "May 18, 2017 to May 24, 2017"
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'date_range_muli' == $params['facet_name'] ) {
$dates = explode( ' to ', $params['facet_value'] );
$params['facet_value'] = date( 'Y-m-d', strtotime( $dates[0] ) );
$params['facet_display_value'] = date( 'Y-m-d', strtotime( $dates[1] ) );
}
@mgibbs189
mgibbs189 / test.js
Last active October 20, 2022 20:49
FacetWP - show reset button only when facets are selected
<script>
/*
Code placement: see the "Javascript" section on https://facetwp.com/how-to-use-hooks/
This assumes that your reset button looks like this:
<a class="my-reset-btn" onclick="FWP.reset()">RESET</a>
*/
(function($) {
@mgibbs189
mgibbs189 / custom-loop.php
Last active September 1, 2022 13:25 — forked from SauntValerian/gist:a79845e301de969017e714a96ffee6da
Multiple Loops for FacetWP
<?php
$args = array(
'post_type' => 'location',
'posts_per_page' => -1,
'order' => 'ASC',
'orderby' => 'title',
'facetwp' => true,
'tax_query' => array(
array(
'taxonomy' => 'advertiser-level',
@mgibbs189
mgibbs189 / functions.php
Last active May 5, 2022 22:17
FacetWP index ACF date in F j, Y format
<?php
/**
* reindex after adding or updating this filter
*/
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'dates' == $params['facet_name'] ) {
$raw_value = $params['facet_value'];
$params['facet_display_value'] = date( 'F j, Y', strtotime( $raw_value ) ); // "April 10, 2019" for the display value
}
@mgibbs189
mgibbs189 / functions.php
Created April 20, 2016 01:48
FacetWP - add a "Load more" button below results
<?php
function fwp_load_more() {
?>
<script>
(function($) {
$(function() {
if ('object' != typeof FWP) {
return;
}
@mgibbs189
mgibbs189 / test.php
Last active March 11, 2022 18:07
FacetWP - change proximity placeholder text
<?php
function change_proximity_label( $translated_text ) {
if ( 'Enter location' == $translated_text ) {
return 'My new placeholder text';
}
return $translated_text;
}
add_filter( 'gettext', 'change_proximity_label' );
@mgibbs189
mgibbs189 / functions.php
Created February 12, 2020 15:11
FacetWP - change cluster icons
<?php
/**
* This assumes a "gmaps" folder within your theme
* Within that folder, add m1.png, m2.png, m3.png, m4.png, m5.png
*/
add_filter( 'facetwp_map_init_args', function( $settings ) {
$settings['imagePath'] = get_bloginfo( 'stylesheet_directory' ) . '/gmaps/m';
return $settings;
});