WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Template
[resolved] [closed] Use only for Custom Post Type (6 posts)

  1. lonchbox
    Member
    Posted 11 months ago #

    Hi,

    Great to know now the plugin support CPTs :)

    But how can I only use for CPTs?, I mean, remove the template selector from normal post.

    Thanx.

    http://wordpress.org/plugins/custom-post-template/

  2. dadra
    Member
    Posted 11 months ago #

    This is exactly what I want to do as well.

    Simon, any thoughts?

  3. lonchbox
    Member
    Posted 9 months ago #

    I think with a filter in funcionts.php is more than enough ;)

  4. oliversos
    Member
    Posted 9 months ago #

    I answered my own question, the code to add is in the "Other Notes" section of the plugin page. Simply add it to functions.php and add your custom post type name:

    /**
    * Hooks the WP cpt_post_types filter
    *
    * @param array $post_types An array of post type names that the templates be used by
    * @return array The array of post type names that the templates be used by
    **/
    function my_cpt_post_types( $post_types ) {
    $post_types[] = 'movie';
    $post_types[] = 'actor';
    return $post_types;
    }
    add_filter( 'cpt_post_types', 'my_cpt_post_types' );

  5. Gabriel Tadeu
    Member
    Posted 9 months ago #

    This is probably not the best way but works: I reset $post_types array or update first position.

    function my_cpt_post_types( $post_types ) {
        $post_types = [];
        $post_types[] = 'projetos';
    
        return $post_types;
    }

    or

    function my_cpt_post_types( $post_types ) {
        $post_types[0] = 'projetos';
    
        return $post_types;
    }
  6. lonchbox
    Member
    Posted 8 months ago #

    It works! :) thanx @gtso86

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic