Skip to content

Instantly share code, notes, and snippets.

add_filter('sanitize_file_name', array(&$this, 'add_extension' ) );
// Download file to temp location
$tmp = download_url( $url );
remove_filter('sanitize_file_name', array(&$this, 'add_extension' ) );
preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $tmp, $matches);
$file_array['name'] = basename($matches[0]);
$file_array['tmp_name'] = $tmp;
@micahwave
micahwave / gist:1603272
Created January 12, 2012 21:33
exlude home posts
/**
* Filter out any lede post ids or hidden posts from the main query
*/
function time_exclude_home_posts( $query ) {
// make sure were on the homepage 1st
if( ( is_home() || is_front_page() ) && $query->is_main_query() ) {
$hidden_post_ids = array();
@micahwave
micahwave / gist:1601778
Created January 12, 2012 17:08
Hide posts on homepage loop
/**
* Where filter to hide posts on the homepage query
*/
function time_hide_posts_where( $where ) {
global $wpdb;
if( is_home() || is_front_page() ) {
$where .= " AND $wpdb->posts.ID NOT IN ( SELECT m.post_id FROM $wpdb->postmeta AS m WHERE m.meta_key = 'time_hide_on_home' AND m.meta_value = 1 )";
@micahwave
micahwave / gist:1556260
Created January 3, 2012 18:42
Guest Author backfill
$guest_posts = get_posts(
array(
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_key' => 'time_guest_author',
'meta_value' => 0,
'meta_compare' => '>=',
)
);
@micahwave
micahwave / gist:1250897
Created September 29, 2011 14:54
update urls export
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1
);
$posts = get_posts( $args );
$slide_args = array(
'post_type' => 'time_slide',
@micahwave
micahwave / gist:1248906
Created September 28, 2011 19:09
entertainment legacy urls
global $wpdb;
$posts = $wpdb->get_results( "SELECT * FROM $wpdb->posts AS p WHERE p.post_type = ('time_slide' OR p.post_type = 'post') AND p.post_status = 'publish'" );
$urls = array();
foreach( $posts as $post ) {
$legacy = get_post_meta( $post->ID, 'time_legacy_url', true );
if( $legacy ) {
$legacy = 'http://www.time.com'.$legacy;
@micahwave
micahwave / gist:1246208
Created September 27, 2011 20:50
Get posts legacy url
$urls = array();
$posts = get_posts( array('posts_per_page' => -1, 'time_post_format' => 'time-post-format-special') );
foreach( $posts as $post ) {
$urls[] = esc_url ( get_post_meta( $post->ID, 'time_legacy_url', true );
}