Last active
February 19, 2018 12:10
-
-
Save stompweb/ade2f0cb3a57fad2a7022deaa0ebd33a to your computer and use it in GitHub Desktop.
Case Studies - Users
This file contains 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 | |
function sj_rewrite_case_studies_users() { | |
hm_add_rewrite_rule( | |
array( | |
'regex' => '^case-studies/([^/]+)/?', | |
'query' => 'author_name=$matches[1]', | |
'template' => 'templates/your-template.php', | |
'title_callback' => function( $title, $seperator ) { | |
return get_query_var( 'author_name' ) . ' case studies ' . $seperator . ' ' . $title; | |
} | |
'request_callback' => function( WP $wp ) { | |
if ( ! username_exists( get_query_var( 'author_name' ) ) ) | |
wp_redirect( get_bloginfo( 'url' ) ); | |
exit; | |
} | |
$wp->query_vars['post_type'] = 'case_study'; | |
$wp->query_vars['author_name'] = get_query_var( 'author_name' ); | |
}, | |
) | |
); | |
} | |
add_action( 'init', 'sj_rewrite_case_studies_users' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment