1

I have a list of custom post types, which includes one called "Tall_Homes" and a home page of six boxes generated from six different custom post type excerpts. They all link successfully to content-single.php, via single.php where

$post_type = get_post_type( $post->ID );

is used to write each page. They all work except for Tall_Homes, which doesn't reach the single.php page. Instead it generates this error:

Warning: include(.../post-template-tallhomes.php): failed to open stream: No such file or directory in ...\wp-includes\template-loader.php on line 74

However, there is no "tallhomes.php" template and this spelling of "tallhomes" is not found in the custom post type setup. I don't know where it's coming from.

Which one of the register_post_type items or args contains the information used to generate the template name? Any idea how to fix this?

Thanks Charles

1

Without seeing more code, on the surface it looks like a typo somewhere because the {$posttype} would be tall_homes.

You could try putting an override function in your theme's functions.php file though that should get around this:

function tall_homes_override( $template ) {
    global $wp_query;
    $post_type = get_query_var( 'post_type' );

    if ( $wp_query->is_single && $post_type == 'tall_homes' ) {
        return locate_template( 'single.php' );
    }
    return $template
}
add_filter( 'template_include', 'tall_homes_override' );

What this should do is that when WordPress goes to look for what template to use, it will test and see if this is a single post and what the post_type is. If it is single and the post_type is tall_homes then it will set it to use single.php instead.

|improve this answer|||||
  • Thank you that forces it to the correct template. I've checked for typos and even searched the content of all my files and can't find an instance of "tallhomes" anywhere. However, I'm wondering if one of the $args that I copied from an online code was overriding the proper redirection. – Charles Mar 21 '18 at 16:39
  • You're welcome. Id have to take a look at the code to see what it is doing. Seems weird that it is only doing it for that one post type though. – Cedon Mar 21 '18 at 18:15
  • 1
    If you want I can post a link to it, but it's probably not worth the time. This is a better way to do it because it's like hard coding it. In fact I added the override to all of the other CPTs in functions as well to make sure none of them get confused. – Charles Mar 22 '18 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.