Skip to content

Instantly share code, notes, and snippets.

View zanematthew's full-sized avatar

Zane Matthew zanematthew

View GitHub Profile
@zanematthew
zanematthew / tracks_controller.php
Created June 16, 2012 16:07
Venue by Region and Local Venues
<?php
/**
* Returns the ID of all Venues in a given Region (full region)
*/
public function getVenueByRegion( $region=null ){
$args = array(
'post_type' => 'tracks',
'posts_per_page' => -1,
'post_status' => 'published',
'meta_query' => array(
@zanematthew
zanematthew / routes.php
Created June 19, 2012 02:48
Custom routes for using WordPress as an Application
<?php
/**
* This file handles redirecting of our templates to our given views
* dir and anything else.
*
* Check if the themer has made a theme file in their
* theme dir, if not load our default.
*
* @uses template_redirect http://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect
*/
@zanematthew
zanematthew / gist:3001237
Created June 27, 2012 03:41
Separating logic
// Snippet from events/index.html.php
<!-- Track -->
<div class="row">
<h2 class="title"><?= $events->getTrackTitle( $post->ID ); ?></h2>
<div class="image-container">
<img src="<?= $tracks->getMapImage( $events->getTrackId( $post->ID ), 'medium' ); ?>" />
</div>
</div>
<!-- -->
@zanematthew
zanematthew / gist:3099863
Created July 12, 2012 18:15
Sample auto loader
<?php
/**
* Start auto loading
*
* Everything is based on the presence of a plugin/your-plugin/controller/{$post_type}_controller.php
* file if this file is present it is read and $post_type is paresed out and used for the model, js,
* and css file. If a css or js file isn't present one will be created for you given we can write to
* the dir.
*/
@zanematthew
zanematthew / upload.php
Created July 23, 2012 16:00
Here's how I'm using zm-upload inside of a plugin and resizing images.
<?php
if ( ! empty( $_FILES ) ) {
$media = new MediaUpload;
$uploaded_media = $media->saveUpload( $field_name='Filedata' );
/**
* @todo MediaUpload does NOT handle resizing of images,
* normally its done in WordPress, but for some reason
@zanematthew
zanematthew / stateByAbbreviation
Created July 25, 2012 14:21
You give me state, I give you abbreviation!
<?php
/**
* You give me state, I give you abbreviation!
*/
public function stateByAbbreviation( $abbr=null ){
if ( is_null( $abbr ) )
die('need abbr');
@zanematthew
zanematthew / gist:3185613
Created July 27, 2012 01:18
Arsh Redirect
<?php
add_action( 'template_redirect', 'boo' );
function boo(){
// ge the global post type
global $post_type;
// this is the one we want to match against
@zanematthew
zanematthew / gist:3199216
Created July 29, 2012 14:23
WordPress Custom Post Type Converter
<?php
/**
* Usage: post_type_converter( 'tracks', 'venues');
*/
function post_type_converter( $from=null, $to=null, $post_id=null ){
global $wpdb;
$query = "SELECT ID, post_type FROM $wpdb->posts WHERE post_type = '{$from}'";
@zanematthew
zanematthew / gist:3199265
Created July 29, 2012 14:38
WordPress Update Meta Key
<?php
/**
* Rename meta keys
* Usage: update_meta_key( 'old_key', 'new_key');
*/
function update_meta_key( $old_key=null, $new_key=null ){
global $wpdb;
$query = "UPDATE ".$wpdb->prefix."postmeta SET meta_key = '".$new_key."' WHERE meta_key = '".$old_key."'";
@zanematthew
zanematthew / events.php
Created August 4, 2012 22:45
Sample Post Type
<?php
$event = new Events();
$event->post_type = array(
array(
'name' => 'Race Event',
'type' => 'events',
'has_one' => 'tracks', // add support 'has_many' => 'other_cpt'
'rewrite' => array(
'slug' => 'events'