Support » Fixing WordPress » Custom post type single page template

  • Resolved Ariel Noname


    Hello guys!

    So I registered a custom post type “products”.
    I have my single-products.php to template the single posts.

    But I want to make an individual template for one of those. Let’s say the post with id=90

    How can I do it?

    Its something like page-90.php but more like post-90.php

    Any ideas?

Viewing 9 replies - 1 through 9 (of 9 total)
  • I tried adding the page-attributes support but the template option isn’t available

    add_filter('single_template', 'my_single_template');
    function my_single_template($single) {
    	if(file_exists(get_template_directory() . '/single-' . get_the_ID() . '.php'))
    		return get_template_directory() . '/single-' . get_the_ID() . '.php';
    	return $single;

    Then just create a file single-90.php,that’s ok!

    That worked perfect man!!!!

    I’m very thankful!

    nice,can we make friends,my email is [email redacted – please keep help/discussion on these forums]

    Please keep help/discussion on these forums –

    @Gyrate360 – the website in your user profile appears to be violating WordPress’s domain name/trademark policy –

    I used the function above to use a custom single post, but no success.
    I used a custom post type for my store so the pages won’t be mixed with regular site pages.
    I have
    and I used single-842.php based on the page checkout id.
    Still not displaying checkout page based on single-842.php
    I am using wordpress 3.8

    Moderator keesiemeijer



    Have you tried it with a single.php template for your custom post type (single-store.php if store is the custom post type name).

    Here is another way to get a template based on the post id:

    add_filter( 'template_include', 'single_id_template', 99 );
    function single_id_template( $template ) {
    	$post_id = get_the_ID();
    	if ( is_single() &&  $post_id ) {
    		$_template = locate_template( array( 'single-' . $post_id .'.php'  ) );
    		$template = ( $_template ) ? $_template : $template;
    	return $template;

    Thanks, the above functions works great. I have a solution, but it was too lengthy. I added the template page option to the custom post type, but it’s ended up been on other pages.

    keesiemeijer, THANKS a lot for last snippet, it saved a lot of time to me =)

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Custom post type single page template’ is closed to new replies.