dpellenwood

Simple Post Type Archive Filter Rewrites

Jun 2nd, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1.     /**
  2.      * Adjust the rewrite rules for News & Events
  3.      *
  4.      * Adds a simple "status" query variable to the News post type archive
  5.      * to allow filtering the archive by a post meta field for event_date.
  6.      * Allowed statuses are: upcoming, past, and posts (for non-event entries).
  7.      * Also allows paging within the status filters.
  8.      *
  9.      * @since   1.0.0
  10.      */
  11.     public function register_event_rewrite_rules() {
  12.         add_rewrite_tag( '%status%', '([^&]+)' );
  13.         add_rewrite_rule( '^news/(upcoming|past|posts)/?$', 'index.php?post_type=news&status=$matches[1]', 'top' );
  14.         add_rewrite_rule( '^news/(upcoming|past|posts)/page/?([0-9]{1,})/?$', 'index.php?paged=$matches[2]&post_type=news&status=$matches[1]', 'top' );
  15.         add_rewrite_rule( '^news/status/(upcoming|past|posts)/?$', 'index.php?post_type=news&status=$matches[1]', 'top' );
  16.         add_rewrite_rule( '^news/status/(upcoming|past|posts)/page/?([0-9]{1,})/?$', 'index.php?paged=$matches[2]&post_type=news&status=$matches[1]', 'top' );
  17.     }
Advertisement
Add Comment
Please, Sign In to add comment