Skip to content

Instantly share code, notes, and snippets.

@micahwave
micahwave / gist:2712965
Created May 16, 2012 18:50
package migrate
function migrate_old_package( $post_id ) {
global $wpdb;
// fix all the slides
$slides = $wpdb->get_results( $wpdb->prepare("
SELECT * FROM $wpdb->posts AS s WHERE s.post_type = 'time_slide' AND s.post_parent = $post_id
"));
foreach( $slides as $slide ) {
@micahwave
micahwave / gist:2630535
Created May 7, 2012 21:19
wp_query derp
// backend, gather the data
if( have_posts() ) {
get_template_part( 'derp' );
}
wp_reset_query();
// front-end, derp.php
<?php while( have_posts() ) : the_post(); ?>
@micahwave
micahwave / gist:2629127
Created May 7, 2012 17:28
wp_query, first post, last post
function time_first_post() {
global $wp_query;
return ( in_the_loop() && $wp_query->current_post == 0 );
}
function time_last_post() {
global $wp_query;
return ( in_the_loop() && $wp_query->current_post == $wp_query->post_count-1 );
}
@micahwave
micahwave / gist:2161421
Created March 22, 2012 18:39
bitly shortlink
/**
* Helper function to get the short url for a post
*
* @param int $post_id
* @return string $url
*/
function time_get_bitly_url( $post_id = null ) {
$post_id = empty( $post_id ) ? get_the_ID() : $post_id;
<media-reference id="media-reference:b1ae49b273d2e307090f6a70670057e5" mime-type="image/jpeg" name="AP Thumbnail Image" source="http://eapcontent.ap.org/jpg/2012/20120314/11/b1ae49b273d2e307090f6a70670057e5.jpg?contentid=b1ae49b273d2e307090f6a70670057e5/fmt=jpg/role=Thumbnail/reldt=2012-03-14T11:05:58/media=Photo/recordid=5ba9fcac175943c58a2915a3ca65020b/authToken=eNoFwrEKwzAMBcAvsnmyLakeNHbI0K3QsdiJAtkMoSSDP77cTb9NchHlykACQPSguR7WqXmpPQXNWwqeoQEVe5CmEAVYnefvtPfyei7fj%2ffdfTvnuKwNIpnHsEQSM0ctsfwBxaUc9Q%3d%3d&amp;token=1331998202_46B3C20C9EE3641CADC69F406362AAD9" alternate-text="John Bishop" height="83" width="128" coding="jpg" />
@micahwave
micahwave / gist:2024189
Created March 12, 2012 19:31
bitly processs
/**
* Cron to process all of the posts that don't have bitly urls
*/
function time_process_bitly() {
global $wpdb;
// get 100 published posts that don't have a bitly url
$query = $wpdb->prepare(
"
@micahwave
micahwave / gist:1996643
Created March 7, 2012 22:20
newsfeed posts by sean
$q = new WP_Query(
array(
'posts_per_page' => -1,
'post__not_in' => array( 1368 ), // skipping http://newsfeed.time.com/2010/05/17/taste-testing-the-worlds-most-alcoholic-beer/
'post_status' => 'publish',
'post_type' => 'post',
'author' => 14074318,
)
)
<?php
function time_disqus_config_js() {
?>
var omnituretracking = function() {
if (typeof omniTrackEv !== 'undefined') {
var username = jQuery('#dsq-comments').find('.dsq-commenter-name:first').text();
omniTrackEv('comment', jQuery.trim(username));
}
}
@micahwave
micahwave / gist:1952277
Created March 1, 2012 19:01
widget cache
function widget($args, $instance) {
extract( $args );
$title = apply_filters('widget_title', $instance['title']);
?>
<?php echo $before_widget; ?>
<?php if ( $title ) echo $before_title . $title . $after_title; ?>
<?php
global $cap, $post;
$cache_key = 'time_widget_'.$this->id;
@micahwave
micahwave / gist:1760940
Created February 7, 2012 17:38
set_thumbnail
$tmp = download_url( $url );
$img = basename( $url );
$info = pathinfo( $img );
$ext = isset( $info['extension'] ) ? '.' . $info['extension'] : '.jpg';
preg_match( '/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG|tmp)/', $tmp, $matches );
//$file_array['name'] = basename( $matches[0] );
$file_array['name'] = str_replace( '.tmp', $ext, basename( $matches[0] ) );
$file_array['tmp_name'] = $tmp;