1

Has anyone else had trouble with single custom post type templates after Wordpress 5.4 update? Mine were fine and then just stopped after update.

1
  • They're fine here, can you be more specific? This isn't a discussion forum but a Q&A site, so we need to be able to write an answer to the question that's true for all people, you need to ask a specific question that can be answered
    – Tom J Nowell
    Apr 5 '20 at 19:49
1

Nothing changed in WP 5.4 regarding singular post types. The template hierarchy remains the same.

E.g for a post type named book WP will try to load the first file it finds in this list:

  • {selected-custom-template}.php
  • single-book-{slug}.php
  • single-book.php
  • single.php
  • singular.php
  • index.php

Your problems cause is elsewhere, if you've followed the standard approach to templates you should see no difference.

3
  • Well, that's what's weird. It was working fine. The slug is "programs" and the single page is "single-programs.php." After the update it stopped.
    – Kevin
    Apr 7 '20 at 17:35
  • Also, tried updating the permalinks, nothing. Tried deactivating and reactivating the plugin, nothing. Tried the same with the theme. Nothing.
    – Kevin
    Apr 7 '20 at 17:58
  • I can't debug code I can't see, and your question asked if anything changed, it didn't. If my answer answers your question can you mark it as accepted?
    – Tom J Nowell
    Apr 7 '20 at 23:59
0

So, I got things working. The single-{postypes} were part of a plugin. These were working fine but stopped after the update. I had to go and add the following filter and then everything started working again.

So, not sure about the root cause but this did work.

I found the answer here: Custom Post Type Templates from Plugin Folder?

function load_single_template( $template ) {
    global $post;

    if ( 'schedule-items' === $post->post_type && locate_template( array( 'single-schedule-items.php' ) ) !== $template ) {
        return plugin_dir_path( __FILE__ ) . 'scheduler/single-schedule-items.php';
    }

    if ( 'programs' === $post->post_type && locate_template( array( 'single-programs.php' ) ) !== $template ) {
        return plugin_dir_path( __FILE__ ) . 'programs/single-programs.php';
    }

    if ( 'faculty-members' === $post->post_type && locate_template( array( 'single-faculty-members.php' ) ) !== $template ) {
        return plugin_dir_path( __FILE__ ) . 'faculty/single-faculty-members.php';
    }

    return $template;
}

add_filter( 'single_template', 'load_single_template' );

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.