Created
May 17, 2019 13:23
-
-
Save sadikyalcin/7c5ff7fe71cae959bf4a0fe07ab89600 to your computer and use it in GitHub Desktop.
Register custom query vars and template hierarchy re-write to load a specific template for a post type
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_register_query_var( $vars ) { | |
$vars[] = 'eb_id'; | |
$vars[] = 'eb_t'; | |
return $vars; | |
} | |
add_filter( 'query_vars', 'prefix_register_query_var' ); | |
function prefix_url_rewrite_templates() { | |
if ( get_query_var( 'eb_id' ) ) { | |
add_filter( 'template_include', function() { | |
return get_template_directory() . '/events-single.php'; // your template | |
}); | |
} | |
} | |
add_action( 'template_redirect', 'prefix_url_rewrite_templates' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment