Skip to content

Instantly share code, notes, and snippets.

@Vinsanity
Created June 30, 2014 14:38
Show Gist options
  • Save Vinsanity/1687c59e1e34b21ff052 to your computer and use it in GitHub Desktop.
Save Vinsanity/1687c59e1e34b21ff052 to your computer and use it in GitHub Desktop.
WP Rewrite Rules for Post Types. Courtesy of DPE David Paul Ellenwood
/**
* 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