Skip to content

Instantly share code, notes, and snippets.

Aaron Ranard aaronranard

Block or report user

Report or block aaronranard

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@aaronranard
aaronranard / custom-taxonomies.php
Last active Aug 29, 2015
WordPress - get custom taxonomies for post
View custom-taxonomies.php
$categories = get_the_terms( get_the_id() , 'service' );
$separator = '<br />';
$output = '';
if($categories){
foreach($categories as $category) {
//$output .= '<a href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '">'.$category->cat_name.'</a>'.$separator;
$output .= $category->name . $separator;
}
echo trim($output, $separator);
}
@aaronranard
aaronranard / acf-gallery.php
Created Apr 8, 2014
WordPress: ACF - Output Gallery
View acf-gallery.php
@aaronranard
aaronranard / cookies.js
Last active Aug 29, 2015
Javascript: Cookie Management
View cookies.js
/**
* determine whether this is the first visit to the animation page
* @param {string} c_name cookie name
* @return {string} cookie value
*/
function getCookie(c_name){
var c_value = document.cookie;
var c_start = c_value.indexOf(" " + c_name + "=");
if (c_start === -1){
c_start = c_value.indexOf(c_name + "=");
@aaronranard
aaronranard / file-upload.js
Last active Aug 29, 2015
Angular: File Uploader
View file-upload.js
$scope.onFileSelect = function($files) {
// https://github.com/danialfarid/angular-file-upload
var file = $files[0];
$scope.upload = $upload.upload({
url: apiEndpoint + '/api/file/upload',
// method: 'POST' or 'PUT',
// headers: {'header-key': 'header-value'},
// withCredentials: true,
//data: {myObj: $scope.myModelObj},
file: file, // or list of files: $files for html5 only
@aaronranard
aaronranard / remove-acf-repeater-row.php
Last active Oct 23, 2015
acf's delete_sub_field call http://support.advancedcustomfields.com/forums/topic/remove-sub_field/ only makes the value null it doesn't actually delete the row. This does.
View remove-acf-repeater-row.php
<?php
/*
* deleteSubField
*
* This function will delete a value of a sub field entirely and replace the rows correctly.
* ACF's built in delete_sub_field only sets the value to null
*
* @param $field_key (string) the field key of the top level custom field
* @param $repeater_key (string) the field key of the repeater element
* @param $post_id (int) the post_id of which the repeater is stored in
@aaronranard
aaronranard / acf-select.php
Created Nov 10, 2015
PHP: WordPress ACF output select field
View acf-select.php
/*
* Displaying a single value's Label
*/
$field = get_field_object('field_name');
$value = get_field('field_name');
$label = $field['choices'][ $value ];
@aaronranard
aaronranard / get-earliest-relative.php
Last active Nov 19, 2015
PHP: WordPress return top most parent ID
View get-earliest-relative.php
<?php
/**
* [Gets the top most parent of a post. If post is top most parent, returns ID]
* @return int [ID of top most parent]
*/
function get_earliest_relative($post){
if ($post->post_parent){
$ancestors=get_post_ancestors($post->ID);
$root=count($ancestors)-1;
$parent = $ancestors[$root];
View Mobile_Detect.php
<?php
/**
* MIT License
* ===========
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
@aaronranard
aaronranard / feature.php
Last active Dec 15, 2015
WordPress: Get the Featured Image
View feature.php
<?php if (has_post_thumbnail( $project->ID )) : ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $project->ID ), 'single-post-thumbnail' ); ?>
<img src="<?php echo $image[0]; ?>" alt="" />
<?php endif; ?>
@aaronranard
aaronranard / address-to-lat-long.php
Created Jul 23, 2013 — forked from bradp/gist:4999343
WordPress: Address to Latitude / Longitude
View address-to-lat-long.php
<?php
function brrad_geocode($street_address,$city,$state){
$street_address = str_replace(" ", "+", $street_address); //google doesn't like spaces in urls, but who does?
$city = str_replace(" ", "+", $city);
$state = str_replace(" ", "+", $state);
$url = "http://maps.googleapis.com/maps/api/geocode/json?address=$street_address,+$city,+$state&sensor=false";
$google_api_response = wp_remote_get( $url );
You can’t perform that action at this time.