Skip to content

Instantly share code, notes, and snippets.

@ptrm
Created September 18, 2010 17:08
Show Gist options
  • Save ptrm/585865 to your computer and use it in GitHub Desktop.
Save ptrm/585865 to your computer and use it in GitHub Desktop.
add_action( 'generate_rewrite_rules', 'custom_post_type_base' );
function custom_post_type_base( $wp_rewrite ) {
$newrules = array();
foreach ( get_post_types( array( '_builtin' => false, 'public' => true, 'rewrite' => array() ), 'objects' ) as $post_type => $post_type_object ) {
$slug = $post_type_object->rewrite['slug'] ? $post_type_object->rewrite['slug'] : $post_type;
$newrules["$slug/?$"] = "index.php?post_type=$post_type";
$newrules["$slug/feed/?$"] = "index.php?post_type=$post_type&feed=rss2";
$newrules["$slug/feed/(feed|rdf|rss|rss2|atom)/?$"] = "index.php?post_type=$post_type&feed=\$matches[1]";
$newrules["$slug/page/?([0-9]{1,})/?$"] = "index.php?post_type=$post_type&paged=\$matches[1]";
}
$wp_rewrite->rules = $newrules + $wp_rewrite->rules;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment