Skip to content

Instantly share code, notes, and snippets.

@mgibbs189
mgibbs189 / test.php
Last active January 10, 2017 20:53
FacetWP - translate strings using gettext
<?php
add_filter( 'gettext', function( $translated_text, $text, $domain ) {
if ( 'fwp' == $domain ) {
if ( 'Start typing...' == $translated_text ) {
$translated_text = 'The new placeholder';
}
}
return $translated_text;
}, 10, 3 );
@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 / test.php
Created September 25, 2015 00:30
FacetWP - index EDD FES (Front End Submissions) multi-select values
<?php
function index_EDD_FES_multiselect( $params, $class ) {
if ( 'product_style' == $params['facet_name'] ) {
$choices = explode( '| ', $params['facet_display_value'] );
foreach ( $choices as $choice ) {
$params['facet_value'] = $choice;
$params['facet_display_value'] = $choice;
$class->insert( $params );
}
@mgibbs189
mgibbs189 / test.js
Last active September 29, 2015 13:39
FacetWP - store post IDs into a cookie
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
var cookie_data = JSON.stringify(FWP.settings.post_ids);
setCookie("fwp_posts", cookie_data, 7);
});
})(jQuery);
function setCookie(cname, cvalue, exdays) {
var d = new Date();
@mgibbs189
mgibbs189 / test-css-approach.php
Last active April 15, 2016 11:46
Load more button (both CSS and shortcode template approaches)
<?php
/*
CSS-template approach
*/
?>
<button class="fwp-load-more" onclick="fwp_load_more()">Load more</button>
<script>
(function($) {
@mgibbs189
mgibbs189 / test.js
Created September 29, 2015 15:29
FacetWP - generate prev/next buttons from cookie data
<div class="nav-wrapper"><!-- placeholder --></div>
<script>
(function($) {
$(function() {
var post_id = <?php echo $post->ID; ?>; // grab the current post ID
var data = getCookie('fwp_posts'); // get the cookie
if ('' != data) {
data = JSON.parse(data);
var pos = data.indexOf(post_id);
@mgibbs189
mgibbs189 / test.js
Created October 5, 2015 12:20
RT Theme fade support
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
$('.product_boxes .box').addClass('fadeIn animated');
});
})(jQuery);
</script>
@mgibbs189
mgibbs189 / test.php
Last active October 5, 2015 12:54
facetwp_facet_filter_posts to override slider logic
<?php
function custom_slider_logic( $response, $params ) {
$facet = $params['facet'];
// Change the facet name
if ( 'YOUR_FACET_NAME' == $facet['name'] ) {
global $wpdb;
$values = $params['selected_values'];
<?php
function my_facetwp_is_main_query( $is_main_query, $query ) {
if ( isset( $query->query_vars['post_type'] ) ) {
if ( 'edd_wish_list' == $query->query_vars['post_type'] ) {
$is_main_query = false;
}
}
return $is_main_query;
}
@mgibbs189
mgibbs189 / test.php
Created October 6, 2015 13:37
FacetWP - support for Enhanced Media Library plugin
<?php
function index_attachment_terms( $object_id ) {
if ( 0 < (int) $object_id ) {
FWP()->indexer->index( $object_id );
}
}
add_action( 'set_object_terms', 'index_attachment_terms' );