Skip to content

Instantly share code, notes, and snippets.

@stompweb
Last active February 19, 2018 12:10
Show Gist options
  • Save stompweb/ade2f0cb3a57fad2a7022deaa0ebd33a to your computer and use it in GitHub Desktop.
Save stompweb/ade2f0cb3a57fad2a7022deaa0ebd33a to your computer and use it in GitHub Desktop.
Case Studies - Users
<?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