Skip to content

Instantly share code, notes, and snippets.

View coffeepostal's full-sized avatar

Adam Farnsworth coffeepostal

View GitHub Profile
@coffeepostal
coffeepostal / sql-selecting-day-week-and-last-week.sql
Last active November 10, 2018 17:32
SQL: Selecting Records from Today, the Current Week, and Last Week
/* Today */
SELECT * FROM ('table') WHERE date = CURDATE()
/* Current Week */
SELECT * price FROM ('table') WHERE YEARWEEK('date') = YEARWEEK(CURDATE())
/* Last Week */
SELECT * FROM ('table') WHERE YEARWEEK('date') = YEARWEEK( CURDATE( ) + INTERVAL 1 WEEK ) LIMIT 0 , 30
@coffeepostal
coffeepostal / css-striped-bg.css
Created November 10, 2018 17:27
CSS: Striped Background Using Repeating Linear Gradient
background: repeating-linear-gradient(
45deg,
#606dbc,
#606dbc 10px,
#465298 10px,
#465298 20px
);
@coffeepostal
coffeepostal / wordpress-remove-archives-text-from-archive-title.php
Last active March 30, 2017 17:31
WordPress: Remove "Archives" from archive.php Title
<?php
// Remove "Archives" from archive.php title
add_filter( 'get_the_archive_title', function ( $title ) {
if( is_category() ): // Swap out conditional for custom post types, etc.
$title = single_cat_title( '', false );
endif;
return $title;
@coffeepostal
coffeepostal / wordpress-get-blog-posts-page-url.php
Created March 8, 2017 20:50 — forked from kellenmace/get-blog-posts-page-url.php
WordPress: Get Blog Posts Page URL in WordPress
<?php
/**
* Get blog posts page URL.
*
* @return string The blog posts page URL.
*/
function km_get_blog_posts_page_url() {
// If front page is set to display a static page, get the URL of the posts page.
@coffeepostal
coffeepostal / wordpress.force.download.php
Last active March 1, 2017 00:52
WordPress: Force Download
<!-- PUT IN download.php: -->
<?php
/*
* This code delivers a file, specified in the URL parameter, as a forced "Save As" download.
*/
// First, get WordPress loaded
require_once('../../../wp-load.php'); // Modify this if necessary
@coffeepostal
coffeepostal / wordpress.add.acf.content.to.search.results.php
Last active March 21, 2017 19:34
WordPress: Add ACF Content to Search Results
/*******************************
ADD ACF TO SEARCH RESULTS
*******************************/
/* Join posts and postmeta tables: http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_join */
function cf_search_join( $join ) {
global $wpdb;
if ( is_search() ) {
$join .=' LEFT JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
@coffeepostal
coffeepostal / jquery.twoDecimalsWhenDecimalsArePresent.js
Created February 17, 2017 23:21
jQuery: Limit Decimals to Two Places Only When Decimals are Present
if(Math.round(val) !== val) {
val = val.toFixed(2);
}
@coffeepostal
coffeepostal / jQuery.addCommasToThousands.js
Created February 17, 2017 23:19
jQuery: Add Commas to Thousands
function commaSeparateNumber(val){
while (/(\d+)(\d{3})/.test(val.toString())){
val = val.toString().replace(/(\d+)(\d{3})/, '$1'+','+'$2');
}
return val;
}
$('#inputID').val(commaSeparateNumber(1234567890));
@coffeepostal
coffeepostal / jQuery.jshint.reset.js
Created February 8, 2017 01:42
jQuery: Tell CodeKit to ignore console.log, unused events and "== vs. ===" errors
/*jshint devel:true */
/*jslint eqeq: true*/
/*jshint unused:false*/
@coffeepostal
coffeepostal / wordpress.custom.login.logo.php
Created February 6, 2017 20:38
WordPress: Custom Login Logo
// Change Login Logo
function my_login_logo() { ?>
<style type="text/css">
#login h1 a, .login h1 a {
background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/assets/images/site-login-logo.svg);
padding-bottom: 2rem;
background-size: 10rem 5rem;
background-position: center top;
background-repeat: no-repeat;
color: #999;