Skip to content

Instantly share code, notes, and snippets.

@isotrope
isotrope / ansel-cfs-select-hook.php
Created April 15, 2015 20:23
Feed in dynamic options to CFS's Select field type
<?php
/**
* Hooking into the CFS Select field and filling it with whatever options we want
*/
/**
* Unfortunately, there only seems to be a hook for ALL OF THE FIELDS!
*/
add_filter( 'cfs_pre_render_fields', 'iso_override_select' );
function iso_override_select( $input_fields ) {
@isotrope
isotrope / sort-some-cats.php
Created April 16, 2015 22:24
Specify posts ordering in an archive but only for specific categories.
<?php
/**
* Sort some cats' posts by meta_key but not all
*/
function iso_some_cats_are_so_meta( $query ) {
// I'd replace the following with something that isn't hard-coded
// If you're already using ACF, maybe an Options page that makes you select the categories
// And then get_option() that option to fill the following array
@isotrope
isotrope / options-loop.php
Last active August 29, 2015 14:19
Smoother sailings with <option> loops
<?php
/**
* Quickie trick to make managing <option> loops easier
*/
/**
* If you store all your options in an array, the output code will be easier to maintain
* You also won't have to worry about typos when creating new <option>s
*/
$options = array(
@isotrope
isotrope / jquery.basejsobjectstarter.js
Created May 18, 2015 15:12
Basic jQuery/JavaScript starter file to re-use. (Also, WP-jQuery-version-safe)
;
MyObject = typeof MyObject === 'undefined' ? {} : MyObject;
(function ($) {
$.noConflict();
MyObject.module1 = {
init : function () {
var _this = MyObject.module1;
@isotrope
isotrope / order-by-menu.php
Created June 1, 2015 12:11
Order a loop based on a normal WordPress menu (Appearance->Menu).
<?php
/**
* Order a set of posts by IDs found in a menu
*/
/**
* Loop through a menu's items and return an array of post_ids.
*
* @param $menu_name Name of a menu (not its location)
@isotrope
isotrope / aaron-you-lazy-launching-vids.php
Last active August 29, 2015 14:22
Quickly thrown together, untested, might not work properly.... but to get an idea
<?php
/**
* Let's say that the vids are a bunch of thumbs.
* I'll loop through them with something like
*/
$specialty_video_oembed = get_sub_field( 'specialty_video_oembed' );
$specialty_video_oembed_data = empty( $specialty_video_oembed ) ? '' : esc_attr( $specialty_video_oembed );
$specialty_thumbnail = get_sub_field( 'specialty_thumbnail' );
@isotrope
isotrope / whats-the-mather-loop.php
Created June 10, 2015 12:59
Two ways to iterate through arrays in PHP for Jon Mather
<?php
// Getting the array
$product_group = rwmb_meta( 'products' );
/**
* Keys =
* $product_group = rwmb_meta( 'products');
* 'sw_swsku';
* 'sw_swdescription';
@isotrope
isotrope / 2fish-fixed-menu-dirty.js
Last active August 29, 2015 14:23
Add a semi-transparent BG to a fixed nav menu
#toip
@isotrope
isotrope / no-js-head
Created September 1, 2015 12:14
HTML .js/.no-js class
<html class="no-js">
<head>
<script>
(function (doc, classToAdd) {
doc.className = (doc.className).replace("no-js", classToAdd);
})(document.documentElement, "js");
</script>
@isotrope
isotrope / steve_enqueue.php
Created September 2, 2015 20:05
Steve enqueue scripts
<?php
add_action( 'wp_enqueue_scripts', 'ss_enqueue_scripts' );
function ss_enqueue_scripts() {
wp_enqueue_script( 'isotope', get_stylesheet_directory_uri() . '/js/isotope.pkgd.min.js', array(), CHILD_THEME_VERSION, true );
wp_enqueue_script( 'steve-stuff', get_stylesheet_directory_uri() . '/js/filters.js', array( 'jquery', 'isotope' ), '0.1' , true );
}