Created
February 19, 2022 14:23
-
-
Save dankoch-cz/877e6aee64866cf00492bd5cb9e15362 to your computer and use it in GitHub Desktop.
Rewrite rules for query vars
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 | |
| //In functions | |
| add_action( 'init', 'rewrite_plays_url' ); | |
| function rewrite_plays_url() { | |
| add_rewrite_rule( 'program/([^/]+)/([^/]+)/([^/]+)?$','index.php?page_id=1&rok=$matches[1]&mesic=$matches[2]&misto=$matches[3]', 'top' ); | |
| add_rewrite_rule( 'program/([^/]+)/([^/]+)?$','index.php?page_id=1&rok=$matches[1]&mesic=$matches[2]', 'top' ); | |
| add_rewrite_rule( 'program/([^/]+)?$','index.php?page_id=1&rok=$matches[1]', 'top' ); | |
| } | |
| add_filter( 'query_vars', 'register_custom_query_vars', 1 ); | |
| function register_custom_query_vars( $vars ) { | |
| array_push( $vars, 'rok' ); | |
| array_push( $vars, 'mesic' ); | |
| array_push( $vars, 'misto' ); | |
| return $vars; | |
| } | |
| //In template | |
| //Get query vars | |
| $year = get_query_var( 'rok', date('Y')); | |
| $month = get_query_var( 'mesic', date('m') ); | |
| $space = get_query_var( 'misto', "" ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment