Skip to content

Instantly share code, notes, and snippets.

@mgibbs189
mgibbs189 / functions.php
Last active Apr 28, 2021
FacetWP - create a dropdown to filter by "min_beds" (minimum range)
View functions.php
<?php
/*
* Facet name: beds
* Facet type: dropdown
* Data source: "min_beds"
*
* This hook will index all values between min_beds and max_beds. If min_beds = 2 and max_beds = 5,
* then the values "2", "3", "4" and "5" will get indexed for this post.
*/
@mgibbs189
mgibbs189 / functions.php
Created Feb 11, 2021
FacetWP - ignore radio facet selections
View functions.php
<?php
// Add to your (child) theme's functions.php
add_filter( 'facetwp_facet_filter_posts', function( $result, $params ) {
if ( 'categories' == $params['facet']['name'] ) {
return 'continue'; // prevent this facet from being processed
}
return $result;
}, 10, 2 );
@mgibbs189
mgibbs189 / functions.php
Created Feb 11, 2021
FacetWP - change flyout layout HTML
View functions.php
<?php
// Add to your (child) theme's functions.php
add_action( 'wp_head', function() {
?>
<script>
(function($) {
$(function() {
if ('object' != typeof FWP) return;
@mgibbs189
mgibbs189 / functions.php
Created Feb 9, 2021
FacetWP - sort resource archive items by title
View functions.php
<?php
// Add to your (child) theme's functions.php
add_action( 'pre_get_posts', function( $query ) {
if ( $query->is_post_type_archive( 'resource' ) ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
}
});
View functions.php
<?php
// Add to your (child) theme's functions.php
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( 2 === (int) $query->get( 'posts_per_page' ) ) {
$is_main_query = false;
}
return $is_main_query;
}, 10, 2 );
@mgibbs189
mgibbs189 / style.css
Created Jan 19, 2021
FacetWP - right aligned checkboxes
View style.css
.facetwp-type-checkboxes .facetwp-checkbox {
background-position-x: 100%;
padding: 0 20px 0 0;
}
@mgibbs189
mgibbs189 / functions.php
Created Jan 18, 2021
FacetWP - translate date picker (3.7.1+)
View functions.php
<?php
// Add to your (child) theme's functions.php
// replace "YOUR_FACET_NAME" with your *actual* facet name
add_filter( 'facetwp_render_output', function( $output ) {
$output['settings']['YOUR_FACET_NAME']['locale'] = [
'weekdays_short' => ['Dom', 'Lun', 'Mar', 'Mié', 'Jue', 'Vie', 'Sáb'],
'months_short' => ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],
'months' => ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
@mgibbs189
mgibbs189 / functions.php
Last active Jan 14, 2021
User Post Type - display user links for upt_user post items
View functions.php
<?php
// Add to your (child) theme's functions.php
add_filter( 'post_link', function( $url, $post ) {
if ( 'upt_user' == get_post_type( $post->ID ) ) {
$user_id = UPT()->get_user_id( $post->ID );
$url = get_author_posts_url( $user_id );
}
return $url;
@mgibbs189
mgibbs189 / test.js
Created Jan 12, 2021
FacetWP - isotope and ensure that images are loaded
View test.js
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
var $grid = $('.columns-3').imagesLoaded(function() {
$grid.isotope({
layoutMode: 'masonry',
itemSelector : '.product',
masonry: {
columnWidth: '.product',
@mgibbs189
mgibbs189 / functions.php
Created Jan 12, 2021
Map Facet - change MarkerClusterer text color
View functions.php
<?php
// Add to your (child) theme's functions.php
add_filter( 'facetwp_map_init_args', function( $settings ) {
for ( $i = 1; $i <= 5; $i++ ) {
$settings['config']['cluster']['styles'][] = [
'url' => FACETWP_MAP_URL . '/assets/img/m' . $i . '.png',
'width' => 53,
'height' => 53,