Skip to content

Instantly share code, notes, and snippets.

View curiouscrusher's full-sized avatar
🛠️

Nate Holland curiouscrusher

🛠️
View GitHub Profile
@curiouscrusher
curiouscrusher / Search By Category Snippet
Last active August 29, 2015 14:23
A search box to show results only from a specified category in Wordpress
<?php $category_id = get_cat_ID('Your Category'); ?>
<form id="yourformid" method="get" action="<?php bloginfo('url'); ?>">
<input type="text" name="s" id="s" size="20" placeholder="Search" />
<input type="hidden" name="cat" value="<?php echo $category_id; ?>" />
<input type="submit" value="Search" />
</form>
@curiouscrusher
curiouscrusher / _SGulpfile.js
Last active August 29, 2015 14:23
A simple Gulpfile for use with the _S Wordpress starter theme. Still working out a few naming conventions.
// Load dependencies
var gulp = require('gulp' ),
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
livereload = require('gulp-livereload'),
sourcemaps = require('gulp-sourcemaps');
// Config variables
var config = new (function(){
this.package = 'wp-content/themes/your-theme-name/',
@curiouscrusher
curiouscrusher / wp-multiple-post-type-query.php
Last active August 29, 2015 14:28
Wordpress query for multiple post types. Lets say you need to query 3 different post types, and load 1 post from each. Without diving headfirst into SQL and Unions, this is a simpler solution. While may not be the most efficient route, it does the job, and if you can spare less than a second of load/query time, it'll solve your problem.
<?php
// Add your post types to the array
$posttypes = array('post_type_1','post_type_3','post_type_3');
$randompost_typs = shuffle($posttypes);
$counter = count($posttypes);
// Add or remove additional post types as needed
for($i=0; $i<$counter;$i++) {
if($randompost_typs[$i]=='post_type_1') {
// I only wanted one post from each, but you can raise or lower the value if needed
$posts_per_page = 1;
@curiouscrusher
curiouscrusher / .zshrc-alias
Last active October 19, 2015 13:18
Some cool bash alias'
alias trash="rm -rf ~/.Trash"
alias sites="cd ~/Sites"
alias cc="rm -rf var/cache var/full_page_cache var/session"
alias apache="sudo apachectl restart"
alias brup="brew update && brew upgrade && brew cleanup && brew prune && brew doctor"
alias wordpress="wget http://wordpress.org/latest.tar.gz"
alias wp-cleanup="tar --strip-components=1 -xzvf latest.tar.gz && trash latest.tar.gz"
alias gut="git"
@curiouscrusher
curiouscrusher / dumpdatabases-mysql.sh
Created December 2, 2015 17:34
A quick shell script to dump all your databases and compress them.
USER="root"
PASSWORD=""
OUTPUT="/Users/yourusername/Sites"
ExcludeDatabases="Database|information_schema|performance_schema|mysql|sys"
databases=`mysql -u $USER -p$PASWORD -e "SHOW DATABASES;" | tr -d "| " | egrep -v $ExcludeDatabases`
for database in $databases; do
echo "Dumping database: $database"
mysqldump -u $USER -p$PASSWORD --databases $database > `date +%Y%m%d`.$database.sql | gzip $OUTPUT/`date +%Y%m%d`.$database.sql
@curiouscrusher
curiouscrusher / Wordpress Makefile
Last active January 11, 2016 16:07
A Makefile to get wordpress up and running, as well as compile sass in your custom theme.
#
# About
# --------------------------------------------------
# This script can:
# - Install a clean WordPress
# - Compile SASS
#
# Requirements
# --------------------------------------------------
@curiouscrusher
curiouscrusher / strip-html-tags.php
Last active July 8, 2016 17:00
If you've ever dealt with Product exports of any kind during a migration, you've probably thought something like "Wouldn't it be nice if I could strip out all these HTML tags in here..." Well now you can! Grab this script, insert your CSV names, and off you go!
<?php
$csvFileNoTags = "products-test.csv"; // Name your new CSV file
$f = fopen($csvFileNoTags, 'w'); // Create the CSV file from above
$export = strip_tags(file_get_contents("products.csv")); // Load the CSV file and strip all tags from it
fwrite($f, $export); // Write the new CSV
fclose($f); // Fin
?>
@curiouscrusher
curiouscrusher / customers.sql
Created May 4, 2017 19:04 — forked from leek/_Magento1_DeleteTestData.md
Magento - Delete All Test Data
SET FOREIGN_KEY_CHECKS=0;
-- Customers
TRUNCATE `customer_address_entity`;
TRUNCATE `customer_address_entity_datetime`;
TRUNCATE `customer_address_entity_decimal`;
TRUNCATE `customer_address_entity_int`;
TRUNCATE `customer_address_entity_text`;
TRUNCATE `customer_address_entity_varchar`;
TRUNCATE `customer_entity`;
@curiouscrusher
curiouscrusher / re-order.liquid
Created May 16, 2018 21:07
Quickly create a re-order button on order.liquid
{% assign reorder_url = "" %}
{% for line_item in order.line_items %}
{% capture reorder_url %}{{ reorder_url | append: line_item.variant_id | append: ':' | append: line_item.quantity | append: ',' }}{% endcapture %}
{% endfor %}
<a href="{{ '/cart/' | append: reorder_url }}" class="btn">reorder</a></td>
@curiouscrusher
curiouscrusher / radio-options.liquid
Created June 14, 2018 18:56
Swap the select dropdowns for radio input types and retain full Slate compatibility
{% unless product.has_only_default_variant %}
{% for option in product.options_with_values %}
<div class="selector-wrapper js">
{%- assign i = forloop.index0 -%}
<h1>
{{ option.name }}
</h1>
{% for value in option.values %}
<input class="" id="SingleOptionSelector-{{ i }}-{{ value | handle }}" data-single-option-selector data-index="option{{ option.position }}" type="radio" name="SingleOptionSelector-{{ i }}" value="{{ value | escape }}"{% if option.selected_value == value %}checked="checked"{% endif %} {% unless current_variant.available %}disabled="disabled"{% endunless %} >
<label for="SingleOptionSelector-{{ i }}-{{ value | handle }}"><span>{{ value }}</span></label>