Last active
November 17, 2015 09:06
-
-
Save tom-monaco/11002210 to your computer and use it in GitHub Desktop.
WordPress to Apache RewriteMap generator
This file contains hidden or 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
<?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