Skip to content

Instantly share code, notes, and snippets.

View nelsonmc's full-sized avatar

Matt Nelson-Abell nelsonmc

  • Minneapolis, MN
View GitHub Profile
# This is a template .gitignore file for git-managed WordPress projects.
#
# Fact: you don't want WordPress core files, or your server-specific
# configuration files etc., in your project's repository. You just don't.
#
# Solution: stick this file up your repository root (which it assumes is
# also the WordPress root directory) and add exceptions for any plugins,
# themes, and other directories that should be under version control.
#
# See the comments below for more info on how to add exceptions for your
@nelsonmc
nelsonmc / mcn-transient-caching-in-wp
Created June 3, 2013 14:22
Uses Wordpress Transient Caching API to save and retrieve content
<?php
// try to fetch cached object
// (this could be a query, a string, HTML, etc)
$object = get_transient('my_cached_object');
if ( empty( $object ) ) {
// if cache is unavailable, then create the object and cache it
$object = new WP_Query(
array(
'post_type' => 'post'
@nelsonmc
nelsonmc / mcn-redirect-in-wp
Created June 3, 2013 14:04
Redirects Wordpress user a different URL (e.g. homepage)
wp_redirect( home_url() ); exit; // redirect to home URL, using 302 temporary redirect code
@nelsonmc
nelsonmc / mcn-get-wp-attachment-imgs
Created June 3, 2013 13:59
Gets all attachment images associated with a Wordpress post
<?php
// Get all attachment images for a post
// Assumes that we are already using global var $post
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID
);