WordPress.org

Support

Support » Plugins and Hacks » Hacks » [Resolved] Plugin Custom Post Type Template WP 3.5

[Resolved] Plugin Custom Post Type Template WP 3.5

  • wilhud
    Participant

    @wilhud

    I am trying to figure out how to hook a template to a custom post type using a plugin. I have tried this code with no success…

    add_filter( 'template_include','include_template_function', 1 );
    
    function include_template_function($template_path ) {
    if ( get_post_type() == 'cast_bios' ) {
    if ( is_single() ) {
    if ( $theme_file = locate_template( array( 'single-cast_bios.php' ) ) ) {
    $template_path = $theme_file;
    } else {
    $template_path = plugin_dir_path( __FILE__ ) .'single-cast_bios.php';
    }
    }
    }
    return $template_path;
    }

    I am using currently using WordPress 3.5. Does anyone see any problems with the above code or know a way I can get this to work?

    Thanks,
    Wil

Viewing 2 replies - 1 through 2 (of 2 total)
  • wilhud
    Participant

    @wilhud

    Digging into it some more, it appears that the function is being triggered, but the get_post_type and is_single functions are returning no values causing the template to not load. I tried changing the priority of when the filter triggers, but that does not appear to change anything. Still receive no values from those functions. Any ideas on what I may be able to do to get those functions to work as needed?

    Thanks,
    Wil

    wilhud
    Participant

    @wilhud

    It appears to have been a permalink issue. I switched the permalinks off and back on and it started working as expected. Shoulda thought of that before. Figured I’d post the resolution in case anyone else had a similar issue.

    Wil

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Plugin Custom Post Type Template WP 3.5’ is closed to new replies.