Skip to content

Instantly share code, notes, and snippets.

Matt Gibbs mgibbs189

Block or report user

Report or block mgibbs189

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mgibbs189
mgibbs189 / functions.php
Last active May 29, 2020
WP Rocket + CDN + FacetWP Template
View functions.php
<?php
// Add to your (child) theme's functions.php
// @link https://docs.wp-rocket.me/article/90-getrocketcdnurl
add_filter( 'facetwp_render_output', function( $output, $params ) {
if ( function_exists( 'get_rocket_cdn_url' ) ) {
$html = $output['template'];
$html = str_replace( get_home_url(), get_rocket_cdn_url( get_home_url() ), $html );
$output['template'] = $html;
@mgibbs189
mgibbs189 / functions.php
Created May 28, 2020
FacetWP - preserve relevancy if both a search and proximity facet are in use
View functions.php
<?php
// Add to your (child) theme's functions.php
add_filter( 'facetwp_filtered_post_ids', function( $post_ids ) {
$facets = FWP()->facet->facets;
if ( isset( $facets['keywords'] ) && ! empty( $facets['keywords']['selected_values'] ) ) {
remove_filter( 'facetwp_filtered_post_ids', [ FWP()->helper->facet_types['proximity'], 'sort_by_distance' ] );
}
return $post_ids;
@mgibbs189
mgibbs189 / functions.php
Last active May 28, 2020
FacetWP - Map facet - turn off bounds
View functions.php
<?php
// Add to your (child) theme's functions.php
add_action( 'wp_head', function() {
?>
<script>
(function($) {
$(function() {
if ( 'undefined' !== typeof FWP && 'undefined' !== typeof FWP.hooks) {
@mgibbs189
mgibbs189 / functions.php
Created May 22, 2020
FacetWP - layout builder - add MP3 URL into an HTML5 audio player
View functions.php
<?php
// Add to your (child) theme's functions.php
// Change "audio-mp3" to your layout builder's item name (which defaults to "el-XXXXX")
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
if ( 'audio-mp3' == $item['settings']['name'] && ! empty( $value ) ) {
ob_start();
?>
<audio controls>
@mgibbs189
mgibbs189 / functions.php
Created May 21, 2020
Click "locate me" automatically
View functions.php
<?php
// Add the following to your (child) theme's functions.php
add_action( 'wp_head', function() {
?>
<script>
window.addEventListener('DOMContentLoaded', function() {
if ('undefined' !== typeof FWP.hooks) {
FWP.hooks.addAction('facetwp/loaded', function() {
@mgibbs189
mgibbs189 / functions.php
Created May 11, 2020
ACF - set "Other data source" equal to "Data source" if empty
View functions.php
<?php
// Add to your (child) theme's functions.php
add_filer( 'facetwp_acf_display_value', function( $value, $params ) {
if ( ! empty( $params['facet_name'] ) ) {
$facet = FWP()->helper->get_facet_by_name( $params['facet_name'] );
if ( ! empty( $facet['source_other'] ) && empty( $value ) ) {
$value = $params['facet_value'];
}
@mgibbs189
mgibbs189 / functions.php
Created May 6, 2020
User Post Type - change post_name
View functions.php
<?php
// Add to your (child) theme's functions.php
add_filter( 'wp_insert_post_data', function( $data ) {
if ( 'upt_user' == $data['post_type'] ) {
$user_id = (int) $data['post_author'];
$user_data = get_userdata( $user_id );
$slug = $user_data->first_name . '-' . $user_data->last_name . '-' . $user_id;
$data['post_name'] = sanitize_title( $slug );
@mgibbs189
mgibbs189 / functions.php
Created May 1, 2020
FacetWP - User Post Type - re-index whenever a user is saved
View functions.php
<?php
/**
* This goes within a user save hook
*
* First, we run a UPT sync to copy the data into the wp_post* tables
* Then we re-index in FacetWP to capture the changes
*/
UPT()->sync->run_sync( $user_id );
@mgibbs189
mgibbs189 / functions.php
Created Apr 28, 2020
FacetWP - hide the "License key" setting
View functions.php
<?php
// Add to your (child) theme's functions.php
add_filter( 'facetwp_settings_admin', function( $settings ) {
unset( $settings['general']['fields']['license_key'] );
return $settings;
});
@mgibbs189
mgibbs189 / functions.php
Created Apr 20, 2020
FacetWP - index disabled variations (post_status = private)
View functions.php
<?php
// Add to your (child) theme's functions.php
add_filter( 'facetwp_indexer_query_args', function( $args ) {
if ( in_array( 'product', (array) $args['post_type'] ) ) {
$args['post_status'] = [ 'publish', 'private' ];
}
return $args;
}, 20 );
You can’t perform that action at this time.