Skip to content

Instantly share code, notes, and snippets.

@tom-monaco
Last active November 17, 2015 09:06
Show Gist options
  • Save tom-monaco/11002210 to your computer and use it in GitHub Desktop.
Save tom-monaco/11002210 to your computer and use it in GitHub Desktop.
WordPress to Apache RewriteMap generator
<?php
// ensure this can only be called from the command line
PHP_SAPI === 'cli' or die('not allowed');
// load Wordpress's guts so we can use the helpful functions
require( dirname(__FILE__) . '/wp-load.php' );
// get all the posts from wordpress
$posts = get_posts(array('posts_per_page' => 5000) );
// create an array of URLs
$urls = array();
foreach( $posts as $post ) {
$urls[] = str_replace(get_home_url(), '', get_permalink($post->ID));
}
// join them with pipes and print them to stdout
$output = join('|',$urls);
echo 'posts ' . $output;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment