Skip to content

Instantly share code, notes, and snippets.

View kingkool68's full-sized avatar
💻
Coding.

Russell Heimlich kingkool68

💻
Coding.
View GitHub Profile
<?xml version="1.0" encoding="UTF-8" ?>
<schema name="wpdata" version="1.1">
<types>
<!-- Geo location fields -->
<fieldType name="latitude_longitude" class="solr.LatLonType" subFieldSuffix="_coordinate"/>
<fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
<fieldType name="boolean" class="solr.BoolField" sortMissingLast="true" omitNorms="true"/>
<fieldType name="integer" class="solr.TrieIntField" omitNorms="true"/>
<fieldType name="long" class="solr.TrieLongField" omitNorms="true"/>
<fieldType name="float" class="solr.TrieFloatField" omitNorms="true"/>
<?php
function action_pre_get_posts( $query ) {
if ( $query->is_tax() && $query->is_main_query() ) {
$meta_query = array(
array(
'key' => 'date',
'compare' => '>=',
'value' => date( 'Ymd' ),
),
array(
<?php
function action_pre_get_posts( $query ) {
if ( $query->is_tax() && $query->is_main_query() ) {
$meta_query = array(
array(
'key' => 'date',
'compare' => '>=',
'value' => date( 'Ymd' ),
),
);
<?php
function action_pre_get_posts( $query ) {
if ( $query->is_tax() && $query->is_main_query() ) {
$meta_query = array(
array(
'key' => 'date',
'compare' => '>=',
'value' => date( 'Ymd' ),
),
);
<?php
function action_pre_get_posts( $query ) {
if ( $query->is_tax() && $query->is_main_query() ) {
$meta_query = array(
array(
'key' => 'date',
'compare' => '>=',
'value' => date( 'Ymd' ),
),
);
@kingkool68
kingkool68 / cache-busting-file-src.php
Last active March 25, 2019 08:48
Replace the `ver` query arg with the file's last modified timestamp (WordPress CSS/JS Cache Busting)
<?php
/**
* Replace the `ver` query arg with the file's last modified timestamp
*
* @param string $src URL to a file
* @return string Modified URL to a file
*/
function filter_cache_busting_file_src( $src = '' ) {
global $wp_scripts;
// If $wp_scripts hasn't been initialized then bail.
@kingkool68
kingkool68 / basic-class-with-actions-and-filters.php
Created May 4, 2018 18:27
A basic example of a class using actions and filters in WordPress
<?php
class Thing {
/**
* Get an instance of this class
*/
static function get_instance() {
static $instance = null;
if ( null === $instance ) {
$instance = new static();
$instance->setup_actions();
@kingkool68
kingkool68 / wp_dump.php
Last active September 5, 2018 03:09
A better dumping function that preservers whitespace making things easier to read.
<?php
if ( ! function_exists( 'wp_dump' ) ) :
/**
* Dump variables preserving whitespace so they are easier to read.
*/
function wp_dump() {
$is_xdebug = false;
if ( function_exists( 'xdebug_dump_superglobals' ) ) {
$is_xdebug = true;
@kingkool68
kingkool68 / index.js
Created November 14, 2017 18:33
AWS Lambda Function for Proxying Requests to S3
/**
* This is a simple AWS Lambda function that will look for a given file on S3 and return it
* passing along all of the headers of the S3 file. To make this available via a URL use
* API Gateway with an AWS Lambda Proxy Integration.
*
* Set the S3_REGION and S3_BUCKET global parameters in AWS Lambda
* Make sure the Lambda function is passed an object with `{ pathParameters : { proxy: 'path/to/file.jpg' } }` set
*/
var AWS = require('aws-sdk');
<?php
// Add `SQL_NO_CACHE` to every SELECT statement
// Helpful for debugging query performance
add_filter( 'query', function( $query ) {
$query = preg_replace( '/SELECT(\s)/i', 'SELECT SQL_NO_CACHE$1', $query, 1 );
return $query;
});