Last active
August 29, 2015 14:11
-
-
Save NatalieMac/cb44b90a4b749f2dd936 to your computer and use it in GitHub Desktop.
Set up multiple views of a single template that appear as subpages in the URL (WordPress)
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
function prefix_cpt_rewrite() { | |
add_rewrite_tag( '%view%', '([^&]+)' ); | |
} | |
add_action( 'init', 'prefix_cpt_rewrite' ); | |
function prefix_cpt_rewrite_rules() { | |
$slug = 'cpt-slug'; | |
$param_name = 'view'; | |
$param_val = 'map'; | |
add_rewrite_rule( | |
$slug . '/([^/]*)/' . $param_val . '/?', | |
'index.php?post_type=' . $slug . '&name=$matches[1]&' . $param_name . '=' . $param_val, | |
'top' ); | |
add_rewrite_rule( | |
$slug . '/([^/]*)/([^/]*)/' . $param_val . '/?', | |
'index.php?post_type=' . $slug . '&name=$matches[2]&' . $param_name . '=' . $param_val, | |
'top' ); | |
} | |
add_action( 'init', 'prefix_cpt_rewrite_rules' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment