Created
June 30, 2014 14:38
-
-
Save Vinsanity/1687c59e1e34b21ff052 to your computer and use it in GitHub Desktop.
WP Rewrite Rules for Post Types. Courtesy of DPE David Paul Ellenwood
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
/** | |
* Adjust the rewrite rules for News & Events | |
* | |
* Adds a simple "status" query variable to the News post type archive | |
* to allow filtering the archive by a post meta field for event_date. | |
* Allowed statuses are: upcoming, past, and posts (for non-event entries). | |
* Also allows paging within the status filters. | |
* | |
* @since 1.0.0 | |
*/ | |
public function register_event_rewrite_rules() { | |
add_rewrite_tag( '%status%', '([^&]+)' ); | |
add_rewrite_rule( '^news/(upcoming|past|posts)/?$', 'index.php?post_type=news&status=$matches[1]', 'top' ); | |
add_rewrite_rule( '^news/(upcoming|past|posts)/page/?([0-9]{1,})/?$', 'index.php?paged=$matches[2]&post_type=news&status=$matches[1]', 'top' ); | |
add_rewrite_rule( '^news/status/(upcoming|past|posts)/?$', 'index.php?post_type=news&status=$matches[1]', 'top' ); | |
add_rewrite_rule( '^news/status/(upcoming|past|posts)/page/?([0-9]{1,})/?$', 'index.php?paged=$matches[2]&post_type=news&status=$matches[1]', 'top' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment