Hi I have question about file names. If I have custom post type, and for template I can create for example single-portfolio.php
and get content of portfolio posts into this file, but i need to get that post not in same file I want get it on individual files for example single-portfolio-post1.php
something like this but second file that I create doesn’t work how can i do that?
Thank you
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.