Skip to content

Instantly share code, notes, and snippets.

@micahwave
Created September 28, 2011 19:09
Show Gist options
  • Save micahwave/1248906 to your computer and use it in GitHub Desktop.
Save micahwave/1248906 to your computer and use it in GitHub Desktop.
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;
$urls[] = array( get_permalink( $post->ID ), $legacy );
}
}
$tmp_file = WP_CONTENT_DIR.'/uploads/urls.csv'; // define filename here if needed
if ( !touch( $tmp_file ) || !is_writeable( $tmp_file ) ) {
error_log( 'dump_rewrite_rules: The file ' . $tmp_file . ' is not writable. Please check the permissions.' );
return;
}
$fp = fopen($tmp_file, 'w');
foreach( $urls as $url ) {
fputcsv($fp, $url);
}
fclose($fp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment