Skip to content

Instantly share code, notes, and snippets.

@joehoyle
joehoyle / gist:2569751
Created May 1, 2012 17:16
WP_Query advanced post_parent
<?php
/**
* Advanced parent querying with WP_Query
*
* This lets you do somethign like:
*/
$query = new WP_Query( array(
@joehoyle
joehoyle / gist:2855923
Created June 2, 2012 00:32
HM_Rewrite
<?php
/**
* HM_Rewrite and HM_Rewrite_Rule are wrappers for the WordPress rewrite / wp query system
*
* The goal of HM_Rewrite and associated fuctions / classes is to make it very easy to add new routing points
* with new pages (as in dynamic pages, post_type_archive etc). It basically wrapps a few tasks into a nice API.
*
* Everything (almost) you need for setting up a new routing page can be done all at once, relying heavily on PHP
* Closures. It essentially wrapps adding to the rewrite_rules, adding your template file to template_redirect,
fastcgi_intercept_errors on;
location ~ \.php$
{
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
Process: GitX [71752]
Path: /Applications/GitXL.app/Contents/MacOS/GitX
Identifier: nl.frim.GitX
Version: 0.8.4 (0.8.4)
Code Type: X86-64 (Native)
Parent Process: launchd [178]
User ID: 501
Date/Time: 2012-07-26 12:20:04.023 +0100
OS Version: Mac OS X 10.8 (12A269)
function jh_plugin_init() {
if ( function_exists( 'w4tc_cdn' ) )
add_action( 'load-post-new.php', '_jh_add_parse_query_action' );
}
add_action( 'init', 'jh_plugin_init' );
function _jh_add_parse_query_action() {
add_action( 'parse_query', '_jh_add_query_var_to_parse_query' );
}
add_action( 'init', function() {
if ( ! function_exists( 'w4tc_cdn' ) )
return;
add_action( 'load-post-new.php', function() {
add_action( 'parse_query', function( $wp ) {
$wp->query_vars['post_type'] = 'page';
} );
function jh_excerpt_length() {
return 50;
}
add_filter( 'excerpt_length', 'jh_excerpt_length' );
add_filter( 'excerpt_length', function() {
return 50;
} );
add_filter( 'wpthumb_post_image_path', $f = function( $path ) {
$dir = wp_upload_dir();
$num = rand( 0, 2 );
$path = $dir['basedir'] . "/test$num.jpg";
return $path;
});
add_filter( 'get_attached_file', $f );