WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Plugin Custom Post Type Template WP 3.5 (3 posts)

  1. wilhud
    Member
    Posted 1 year ago #

    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

  2. wilhud
    Member
    Posted 1 year ago #

    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

  3. wilhud
    Member
    Posted 1 year ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic