You should be using the template_include filter for this:
add_filter('template_include', 'wpse_44239_template_include', 1, 1);
function wpse_44239_template_include($template){
global $wp_query;
//Do your processing here and define $template as the full path to your alt template.
return $template;
}
template_redirect
is the action called directly before headers are sent for the output of the rendered template. It’s a convenient hook to do 404 redirects, etc… but shouldn’t be used for including other templates paths as WordPress does this innately with the ‘template_include’ filter.
template_include
and single_template
hooks deal ONLY with the path of the template used for rendering the content. This is the proper place to adjust a template path.
Update from comment by @ChipBennett:
single_template
has been removed as of 3.4. Use {posttype}_template instead.
Related Posts:
- single-{$post_type}-{slug}.php for custom post types
- Redirect custom post type category to other custom post type category
- Setup template_redirect using has_term when NO term assigned
- make permalink go to a custom single.php file
- Redirect drafted post of custom post type to URL?
- Custom post type role permissions won’t let me read
- Showing User’s Post Counts by Custom Post Type in the Admin’s User List?
- Can’t get post id on page that is a custom post type archive
- Set default custom post type for XML-RPC
- Is it possible to change the URL of custom post types to hide the post type slug?
- Querying custom post type with 2 custom fields (date-range)
- Is it possible to create an “export to PDF” option?
- manage posts custom column is not populating data from meta boxes
- Add custom field to media attachment image attribute in post editor
- How can i link post_row_actions() with a custom action function
- How can you make permalink work for custom post type and taxonomy?
- Too much recursion error when chosing image from image library for two different meta boxes in one post
- Count custom post types with a specific meta value
- The editor has encountered an unexpected error. // TypeError: Cannot read property ‘prefix’ of null
- Post Rank on Single Post page based on custom field
- Customized first post techniques
- Control Custom Post Type template from a plugin
- WordPress User Roles, Custom Post Types, and Admin views
- Storing Custom Post Type Data in a Custom Table
- `post_type` => `any` not giving me my custom post
- Custom Permalink for Taxonimie and Custom Post Type
- WP_Query that filters based on custom relationship field
- I am having a problem with form updating/editing WordPress post on the frontend
- Adding the taxonomy before the custom post type
- Combine query_posts() and get_posts() into single query
- Use post as category
- How do I create filters for custom post types?
- Duplicate Custom Header Functionality into the post edit screen
- Enqueueing scripts and styles multiple CPTS
- Randomize Posts. Skip the first post in ascending order
- Customize the Dashboard Menu Editor
- How to allow visitors to enter custom post type?
- Why are taxonomy terms not saving when using custom meta boxes with radio button taxonomy selectors?
- How to render a custom post type template with custom fields using shortcode
- How to handle a CSV with 65,000+ rows and make it searchable?
- Static page determines as home, but it is not
- I am having Trouble to get list of Categories of Custom post Type
- How to query WordPress posts bycustom field with a max characters’ length
- Use the same date-based permalink structure for all post types
- Limit the post for differents custom post type in the same wp_query
- meta box on custom post type
- Categories filtering in new post
- categories should be available across all custom post types
- Pagination custom post type not working with rewrite slug
- Automatically create child custom post when creating a custom post
- How can I have different content for different countries?
- ACF repeater field usage
- Show Posts to Author Only
- WP_Query parameter conflict
- Create a comments template for custom post types
- Is it possible to add posts and images (auto resize) for custom post types with a script?
- Retrieving meta-box from a custom-post-type
- Loop through posts of only 2 statuses
- providing access to post_id or post inside functions.php
- CPT with its own category and tag url
- Overriding Plugin Function in Child Theme
- Display custom posts for each category from its custom taxonomy
- Function to limit number of custom post types on homepage – TwentyTen
- Get custom category ID of current custom post within the loop
- Post query missing an elseif statement
- How to limit what Editors see in the admin?
- Custom Post Type not working with Capabilities
- Custom Post Type Template Insert not working properply
- Custom Post Type Pagination on Single.php?
- display custom post on separate page
- Add custom post type to query
- How does one go about converting custom post type to post format?
- How to display magic field’s custom write panel in wordpress theme?
- Admin slow on Postlist (over 30k Posts in Database)
- Disable single page for a custom post type based on a custom field
- Add html tot CPT edit screen – no metabox
- Show all post type posts in manage users posts column
- Setting Custom Post Type Parents/Hierarchies
- Query to Exclude Child Pages from Custom Post Type Archive
- Modify category permalink to use post type slug
- Getting a Post ID to show its content in a Popup
- search results to show individual ACF fields from inside custom posts
- How to make password protected posts that will expire after they are used?
- How to get post type archive category title
- Automatically / dynamically populating tags in custom post type
- Remove CPT Slug with 2 taxonomies and 1 post meta
- How can i order my posts by post type?
- Single Page of Custom Post Type Not Showing the Content Of post
- Multiple loops for custom post type to spread data across rows
- Generate slug and meta data if meta field is empty
- Why is a custom post type’s URL “/?cposts=name-of-the-post” but default post’s URL is “/?p=ID”?
- Roots: Custom Post Type 404 Not Found [duplicate]
- WP_Query get posts where post_name is empty
- Display all post types together
- Custom Post Type Tags Showing Under Regular Post Tags
- Taxonomy and Rewrite Structure
- Nested loop called with shortcode duplicating the content above the main loop
- Pagination for event query
- Problem retrieving custom field for a custom post type
- Remove custom meta boxes from custom post type