Skip to content

Instantly share code, notes, and snippets.

View jackgregory's full-sized avatar

Jack Gregory jackgregory

View GitHub Profile
@jackgregory
jackgregory / functions.php
Created December 21, 2017 13:08
Match exact search term including tax/terms
add_filter( 'posts_search', 'my_search_is_perfect', 20, 2 );
function my_search_is_perfect( $search, $wp_query ) {
global $wpdb;
if ( empty( $search ) )
return $search;
$q = $wp_query->query_vars;
$n = !empty( $q['exact'] ) ? '' : '%';
@jackgregory
jackgregory / facets.php
Last active October 6, 2017 11:31
Listing Facets/Template
function register_facets( $facets ) {
$facets[] = array(
'label' => __( 'Group', 'aplatform' ),
'name' => 'group',
'type' => 'fselect',
'multiple' => 'no',
'source' => 'acf/field_5s9a5l2s921df', // acf select field
'label_any' => __( 'everything', 'aplatform' ),
'orderby' => 'display_value',
'count' => '100',
@jackgregory
jackgregory / functions.php
Created September 25, 2017 10:46
Display user last login time/date
/**
* Capture user login and add it as timestamp in user meta data
*
*/
function 12kdksd212_user_last_login( $user_login, $user ) {
update_user_meta( $user->ID, 'last_login', time() );
}
add_action( 'wp_login', '12kdksd212_user_last_login', 10, 2 );
@jackgregory
jackgregory / htaccess
Created October 12, 2015 14:08
Fonts Allow Control Allow Origin
<ifModule mod_headers.c>
Header set Access-Control-Allow-Origin: *
</ifModule>
@jackgregory
jackgregory / functions.php
Last active September 27, 2015 16:42
Add pagination to WooCommerce product shortcodes
function c4a8a13f4e5_woocommerce_shortcode_products_query( $query_args, $atts ) {
$query_args['paged'] = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
return $query_args;
}
add_filter( 'woocommerce_shortcode_products_query', 'c4a8a13f4e5_woocommerce_shortcode_products_query', 10, 2 );
function c4a8a13f4e5_shortcodes_pagination() {
@jackgregory
jackgregory / functions.php
Created April 14, 2015 08:27
Exclude pages from Jetpack top posts widget
/**
* Exclude pages from Jetpack top posts widget
*
* @param array $posts
* @param array $post_ids
* @param int $count
* @return array
*/
add_filter( 'jetpack_widget_get_top_posts', 'exclude_widget_get_top_posts', 10, 3 );
@jackgregory
jackgregory / gist:2ef8e0ddc3af61af0a6b
Last active October 26, 2016 15:03
WordPress Mysql Search and Replace
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');
@jackgregory
jackgregory / gist:a9f30668c022e8530185
Last active February 16, 2017 11:45
WooCommerce Search by SKU
add_filter( 'posts_where', 'search_by_sku' );
function search_by_sku( $where ) {
if( ! is_search() ) {
return $where;
}
global $wpdb;
$query = get_search_query();
@jackgregory
jackgregory / sitelink-search.liquid
Created November 1, 2014 16:27
Search in Sitelinks Shopify Snippet
@jackgregory
jackgregory / gist:c9912143cc4a8a13f4e5
Last active August 29, 2015 14:04
WooCommerce - Add a low stock note to cart items
add_filter( 'woocommerce_cart_item_name', 'cart_low_stock_note', 10, 3 );
function cart_low_stock_note( $title, $cart_item, $cart_item_key ) {
if( $cart_item ) {
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
$output = '';
$output.= $title;
// threshold
if( $_product->get_stock_quantity() <= 4 ) {