You can use the dynamic filter {type}_template
(where {type}
is the current query type e.g. single
, index
etc.) found in get_query_template()
:
function wpse_204848_get_id_template( $template ) {
if ( $post = get_queried_object() ) {
if ( $_template = locate_template( "single-{$post->post_type}-{$post->ID}.php" ) )
$template = $_template;
}
return $template;
}
add_filter( 'single_template', 'wpse_204848_get_id_template' );
For a portfolio post of ID 5
, it will use the template single-portfolio-5.php
if it exists.
Related Posts:
- single-{$post_type}-{slug}.php for custom post types
- Template for specific post of custom post type
- Multiple Single Post templates
- Custom Post Type with Nested Taxonomy and Template Files
- Single page template for custom post_type
- Trying to manage templates on a blog with lots of custom taxonomies
- Include custom post type single template, but respect theme override of template if it exists
- WordPress Doesn’t Generate Taxonomy Archive
- Custom Empty Results page for my Custom Post Type
- Templates for hierarchical custom post type
- Custom Post Type homepage template
- Templating advice sub posts of a CTP
- taxonomy – templates are not loading
- Templates for CPT not working
- WordPress Custom Post Type – Post Attribute: Template. Template shows up and saves on the back end, but the default theme file is being rendered
- Single taxonomy for different custom post types
- Custom Homepage As Single Page or Custom Post Type?
- tag.php doesn’t work with tags on a custom post type post?
- Assign single template to multiple custom post types?
- Add Content to Page without shortcodes
- How to set a fall back template for a custom post type in a plugin?
- Display Editable Text Above CPT Archive Listings
- Custom taxonomy query for a custom post type
- Need some templating advice for templating with custom post types and taxonomies
- Template tags to display custom post type posts in category template?
- How do I create new content pages for my Custom Post Type?
- custom post type archive template per custom taxonomy term
- Display posts of child category in template
- custom taxonomy – Template not working
- Archive or taxonomy pages not working for custom post type
- Create separate template for shared custom taxonomy with shared terms
- Custom Post Type Templates?
- Custom Post Type .current-menu-item not applying on Custom Post Type Archive Page
- Lock post meta block at the bottom of a custom post type
- How do I provide a “show all posts” link in a paginated term archive?
- How can I force custom post type to use a specific template?
- Multiple templates for a custom post type
- Plugin templates in which directory
- WordPress Ignoring My Custom Post Type Templates?
- Custom post type not using it’s own single-postname.php
- Using wordpress template tags within an array
- Custom post type not using custom template
- Query with no terms uses index.php template instead of archive.php
- Create template for taxonomy results limited by Custom Post Type
- WordPress Custom Post Type Children Template
- Getting template_include to work when allow_url_include is off?
- 2 Templates 1 custom post type according url
- Custom post type showing index.php
- How do I check if the user is on a taxonomy term parent, child or grandchild page?
- Migrating a taxonomy’s tags to the native category
- Custom templates for a specific category
- How to Create Template File for Parent Page of Custom Post Type
- Custom posts template page
- Add Previous/Next Buttons to CPT Single Pages Only
- Creating separate feeds for custom post types
- How to get_term_meta on single custom post?
- Custom Post Type Template Hierarchy – Single post template
- How do I find a way to create a global single.php for a custom post type?
- How to use single.php for creating, reading and editing Custom Posts with ACF
- Apply template by path/slug related to custom post type?
- How to get the current category with custom posts
- Assign a template to a custom post type when displayed by the main loop on the home page
- How to create a archive template for custom post type [duplicate]
- WP not recognizing custom post type / template
- Create a custom taxonomy template that loops through child categories in term order?
- My template won’t apply, theme still fallback to index.php
- One Custom Post Type two different Templates
- Conflict in function to allow single post template based on category
- How to make post templates to include shortcodes only?
- On click some element i want to use some template
- Post template with breadcrumb needs to show page navigated from
- Custom Post Taxonomy Template Not Loading Properly
- Accessing download link from the loop with WP Download Manager Pro
- Turning archive templates to a page template maintaining the slug
- How do I control what template is shown based upon Taxonomy Term?
- get_permalink() of page the enclosing page not posts
- How to Create a Default Fixed Custom Posts layout for text and images
- Why did permalinks setting affect the pages?
- How to make a custom search template for custom taxonomy?
- Custom post type with two templates
- Custom Post Type tag taxonomy “Page Not Found”
- DIVs not showing correctly on CPT?
- Why isn’t my custom post type using the corresponding custom post template?
- Load different template for CPT (in loop) in my plugin?
- Search page for custom post type
- Custom post type category page not working
- CPT Template Not Showing – Getting 404
- Custom Post Type Template based on Taxonomy
- Template with Custom Post Type (Custom Tables) does not work
- How can I sort posts ascending by post title for a specific post type, but on a category archive template?
- Specifying Default Template for Hierarchal Custom Post Type [duplicate]
- Most appropriate way to display CPT’s by children terms of custom taxonomies while retaining desired permalink structure?
- how to pass args for archive.php query?
- Navigation links to posts in current term shortcode
- CPT Template Option to Top
- WP_Query is getting the post but the_post() not rendering any Post
- Show my custom post id if a country or ip
- How to create custom page templates with default page layout framework?
- Custom taxonomy meta fields
- Why isn’t page attributes dropdown not showing up in a custom post type