Skip to content

Instantly share code, notes, and snippets.

@larryfox
larryfox / LICENSE.txt
Last active February 22, 2022 21:27
Determine if an elements background color is light or dark!
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2015 Larry Fox <http://larryfox.us>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@jchristopher
jchristopher / gist:945ce9088423c9679b49
Last active August 29, 2015 14:08
Set up a custom wrapper div for facetwp-template in Genesis
<?php
// open the FacetWP Template wrapper
function be_open_facetwp_template_wrapper() {
echo '<div class="facetwp-template">';
}
add_action( 'genesis_before_loop', 'be_open_facetwp_template_wrapper', 9999 );
// close the FacetWP Template wrapper
@hissy
hissy / really-simple-csv-importer-addon.php
Created February 25, 2015 14:01
[Really Simple CSV Importer] Example: import image from url to custom field
<?php
/*
Plugin Name: Get Remote Image to Custom Field
*/
add_filter('really_simple_csv_importer_post_saved', function($post)
{
if (is_object($post)) {
// Get the meta data of which key is "image"
$image = $post->image;
@jchristopher
jchristopher / functions.php
Last active January 26, 2022 23:24
Automatically link to WooCommerce Product Variation detail when searching for a Product Variation SKU
<?php
// When using SearchWP it's necessary to disable WooCommerce's insistance on
// automatically redirecting to a single search result without showing the
// search results page, when that happens this hook doesn't run!
// Willing to bet this can be edited to accommodate, tips are welcome!
add_filter( 'woocommerce_redirect_single_search_result', '__return_false' );
function my_maybe_woocommerce_variation_permalink( $permalink ) {
if ( ! is_search() ) {
@swissspidy
swissspidy / language-updates-table.php
Last active April 4, 2020 11:20
Display a table with available translation updates on the WordPress update screen
<?php
/**
* Plugin Name: Translation Updates Table
*
* @author Pascal Birchler <pascal@required.ch>
* @license GPL2+
*/
/**
* Displays a table with available translation updates.
@djrmom
djrmom / custom-hooks.php
Last active February 16, 2018 21:01
facetwp force query args
<?php
/** to use this make sure all queries to be used
** for facets have 'facetwp' => true in query args, including the
** query args setting in a facetwp template
**/
// add 'facetwp' => false anytime it is not already set
add_action( 'pre_get_posts', function( $query ) {
if ( ! isset( $query->query_var['facetwp'] ) ) {
$query->set( 'facetwp', false );
<?php
add_filter( 'facetwp_filtered_post_ids', 'car_zero_priced_last', 10, 2);
function car_zero_priced_last( $post_ids, $class ) {
if (!isset($class->ajax_params['http_params']['get']['fwp_sort'])) {
return $post_ids;
}
if (isset($class->ajax_params['http_params']['get']['fwp_sort']) && $class->ajax_params['http_params']['get']['fwp_sort'] != 'price_asc') {
return $post_ids;
@djrmom
djrmom / custom-hooks.php
Last active September 26, 2020 15:15
facetwp only products
<?php
/* only filter product queries */
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( 'product_query' != $query->get( 'wc_query' ) ) {
$is_main_query = false;
}
return $is_main_query;
}, 10, 2 );
@mgibbs189
mgibbs189 / test.html
Created March 28, 2018 16:31
Manually replace sort box with fSelect
<link href="path/to/fSelect.css" rel="stylesheet" type="text/css">
<script src="path/to/fSelect.js">
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
$('.facetwp-sort-select').fSelect();
});
})(jQuery);
</script>
@mgibbs189
mgibbs189 / functions.php
Last active April 17, 2018 11:14
FacetWP - pass ACF data into template
<?php
/**
* To access the data within the "Query Arguments" box, use:
* $this->http_params['choose_city']
*/
add_action( 'wp_footer', function() {
$choose_city = get_field( 'choose_city' );
?>