Skip to content

Instantly share code, notes, and snippets.

@typeofweb
Created April 4, 2013 10:17
Show Gist options
  • Save typeofweb/5309306 to your computer and use it in GitHub Desktop.
Save typeofweb/5309306 to your computer and use it in GitHub Desktop.
<?
/*
Template Name: XML Template
*/
$qry = $wpdb->get_results("
SELECT SUBSTR(
CONCAT(
REPLACE(
REPLACE(
REPLACE(
REPLACE(wpo.option_value,'%year%',date_format(wpp.post_date,'%Y'))
,'%monthnum%',date_format(wpp.post_date,'%m'))
,'%day%',date_format(wpp.post_date,'%d'))
,'%postname%',wpp.post_name )
)
, 2) as permalink FROM wp_posts wpp INNER JOIN wp_options wpo on wpo.option_name='permalink_structure' WHERE wpp.post_type = 'post' AND wpp.post_status = 'publish' ORDER BY wpp.post_date DESC");
$ret = "";
foreach ($qry as $it) {
$ret .= 'RewriteCond %{HTTP_HOST} ^olddomain.com [NC]' . "\n";
$ret .= 'RewriteRule ^' . $it->permalink . '$ http://newdomain.com/' . $it->permalink . " [R=301,L]\n";
}
header("Content-Type: text/plain");
echo $ret;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment