Created
September 28, 2011 19:09
-
-
Save micahwave/1248906 to your computer and use it in GitHub Desktop.
entertainment legacy urls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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