Skip to content

Instantly share code, notes, and snippets.

@micahwave
micahwave / gist:4018279
Created November 5, 2012 16:53
publish package slides
/**
* Make slide post_status mirror the post status of the parent post
*
* Using $wpdb to update the values because I don't want to toggle all our other actions
*/
function time_transition_package_status( $new_status, $old_status, $post ) {
global $wpdb;
// this is only for posts
@micahwave
micahwave / gist:3928578
Created October 21, 2012 21:30
rewrite rules
/**
* Custom endpoints, rewrite rules for contributors page tabs
*/
function time_rewrite_rules() {
global $wp_rewrite;
add_rewrite_tag( '%photo%', '([^&]+)' );
add_rewrite_tag( '%slide%', '([^&]+)' );
add_rewrite_tag( '%tab%', '([^&]+)' );
@micahwave
micahwave / gist:3364024
Created August 15, 2012 21:52
guest author latest post
/**
* Add the most recent post id to each guest author as meta
*/
function time_guest_author_latest_post( $post_id, $post ) {
if( $post->post_type == 'post' ) {
$guest_id = get_post_meta( $post_id, 'time_guest_author', true );
if( $guest_id ) {
@micahwave
micahwave / gist:3317698
Created August 10, 2012 20:44
guest author madness
/**
* Returns an array of contributors and stories based on passed tab.
*
*/
function time_get_contributors( $tab = 'all' ) {
global $wpdb, $wp_query;
$contributors = wp_cache_get( 'time_contributors_'.$tab, 'time_contributors_cache' );
document.write('<!-- New High Impact Trigger -->\n');
window.responsiveAd.highImpact( "sidebar", 468, 648 );
document.write('<!-- Template Id = 12195 Template Name = TIM - High Impact 1x1 - 468x648 -->\n');
highAdLayout('468','648');
document.write('\n\n');
adid="260411135";
document.write('');
@micahwave
micahwave / gist:3240092
Created August 2, 2012 19:53
tax query
$latest_galleries = wp_cache_get( 'latest_galleries', 'time_gallery_cache' );
if( !$latest_galleries ) {
$latest_galleries = get_posts( array(
'posts_per_page' => 6,
'post_status' => 'publish',
'tax_query' => array( array(
'taxonomy' => 'time_post_format',
'field' => 'slug',
@micahwave
micahwave / gist:3183795
Created July 26, 2012 18:53
Group by order by
"
SELECT g.*, p.ID as article_id, p.post_title as article_title
FROM $wpdb->posts AS g
LEFT JOIN $wpdb->postmeta AS pm ON pm.meta_value = g.ID
LEFT JOIN $wpdb->posts AS p ON pm.post_id = p.ID
LEFT JOIN $wpdb->postmeta AS pm2 ON pm2.post_id = g.ID
WHERE g.post_type = 'time_guest'
AND pm.meta_key = 'time_guest_author'
AND pm2.meta_key = 'time_guest_time100'
AND ( pm2.meta_value = 'on' OR pm2.meta_value = 1 )
@micahwave
micahwave / gist:3172454
Created July 24, 2012 20:33
responsive img
time_the_post_thumbnail( 'l', array(
'breakpoints' => array(
'0' => 'm 1x, l 2x',
'476' => 'l 1x, xxl 2x',
'951' => 'xl 1x, xxl 2x',
)
));
function render_tweet_text( data ) {
if( typeof data.tweets != undefined ) {
jQuery('#sponsor_content').html( format_links( data.tweets[0].text ) );
}
}
function format_links( str ) {
str = ' '+str;
str = str.replace(/((ftp|https?):\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?)/gm,'<a href="$1" target="_blank">$1</a>');