Skip to content

Instantly share code, notes, and snippets.

@mgibbs189
mgibbs189 / functions.php
Last active April 28, 2021 15:17
FacetWP - create a dropdown to filter by "min_beds" (minimum range)
<?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 February 11, 2021 19:49
FacetWP - ignore radio facet selections
<?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 February 11, 2021 19:09
FacetWP - change flyout layout HTML
<?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 February 9, 2021 19:10
FacetWP - sort resource archive items by title
<?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' );
}
});
<?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 January 19, 2021 14:15
FacetWP - right aligned checkboxes
.facetwp-type-checkboxes .facetwp-checkbox {
background-position-x: 100%;
padding: 0 20px 0 0;
}
@mgibbs189
mgibbs189 / functions.php
Created January 18, 2021 16:13
FacetWP - translate date picker (3.7.1+)
<?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 January 14, 2021 14:18
User Post Type - display user links for upt_user post items
<?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 January 12, 2021 17:59
FacetWP - isotope and ensure that images are loaded
<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 January 12, 2021 14:46
Map Facet - change MarkerClusterer text color
<?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,