WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Template
custom post types (9 posts)

  1. bphil00
    Member
    Posted 2 years ago #

    Hey, so support for custom post types isn't working for me. The plugin is working on standard posts though.

    I put this at the bottom on my functions.php file:

    /**
     * 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[] = 'Items';
        return $post_types;
    }
    
    add_filter( 'cpt_post_types', 'my_cpt_post_types' );

    I have one custom post type, named Items.
    Is there some other code I need to put somewhere in addition to this?

    Also, in the Other Notes section on the plug-in's page, it says "You can ALSO add this code to the functions.php file in your theme." But it doesn't say where it would be placed otherwise. Where does it go if you're not putting it in functions.php?
    Sorry if this a dumb question, I'm new to this.

    Thanks in advance, I'm looking forward to utilizing this plug-in!

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

  2. Simon Wheatley
    Code for the People
    Plugin Author

    Posted 2 years ago #

    Hi bphil00,

    Can you post the code you're using to register your custom post type, please?

  3. bphil00
    Member
    Posted 2 years ago #

    sure, here it is:

    [Code moderated as per the Forum Rules. Please use the pastebin]

  4. bphil00
    Member
    Posted 2 years ago #

    damn it, moderator!
    I'm at work now, I'll repost using pastebin when I get home this evening. Sorry about that.

  5. Simon Wheatley
    Code for the People
    Plugin Author

    Posted 2 years ago #

    It's OK. I think the problem might be where you have register_post_type( 'Items', … WordPress is transforming to items (note lowercase).

    Accordingly, try changing your $post_types[] = 'Items'; to $post_types[] = 'items'; (again, note lowercase).

    Let me know how that is for you.

  6. bphil00
    Member
    Posted 2 years ago #

    Thank You!
    I'll try it when I get home and update you.

  7. bphil00
    Member
    Posted 2 years ago #

    okay, I changed the uppercase 'Items' to 'items' and it worked! The meta box now shows up in the custom post editor. Unfortunately it's not applying the template to the post's page when viewing it.

    Here's the code I used to register it:
    http://pastebin.com/hvHDqFk1

    Any idea why it's not applying the template?

  8. bphil00
    Member
    Posted 2 years ago #

    Actually, when I load that post it uses the 404 template.
    I'm at a loss here as to why this is happening.

  9. bphil00
    Member
    Posted 2 years ago #

    Well... damn, it's a great idea for a plugin and definitely one that should be part of the wordpress core.
    Let me know if you get it functional, in the meantime, I guess I'm back to the drawing board.

    Anyone know of a plugin that adds custom templates to posts??

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic