I was doing a WordPress project this week that required four custom post types along with associated taxonomies and metaboxes. It’s been a while since I’ve done client work, and realized I didn’t have good boilerplate code to build these custom post type plugins from.
In the past, I’ve altered the “Portfolio Post Type” plugin which I’ve written but this has become more specialized for portfolios as Gary Jones and I have worked on it and isn’t as great a starting place as it used to be.
I think it’s really important to have quality code lying around for items like this. Building a custom post type (and especially metaboxes) from scratch each time can be a huge time waste. So, I’m throwing the final product up on GitHub in case others want to fork it and use it as their boilerplate as well.
It’s a “Team” post type and essentially does five things:
- Registers a post type
- Registers a custom taxonomy
- Registers a few metaboxes (Title, Twitter, Facebook, LinkedIn)
- Adds the featured image to the admin column display
- Adds the post count to the admin dashboard
Even though it’s designed for a “team”, it just takes a couple minutes to go through and alter everything to make it work for a different type of data.
If you see anything huge I missed, feel free to send a pull request. I hope it saves you some time on your next project! View the code.
Nice work! I always use the GenerateWP generator, it’s always been a fantastic tool just for this purpose.
http://generatewp.com/post-type/
Yep, that’s a great tool. Someone could even use that to generate the $labels and $args there, and then paste it into this plugin wrapper.
Hi Devin, thank you very much for sharing!
I have installed the plugin, and everything works fine except “menu_position” option, which seems not to work, and always appears in the admin sidebar under “settings”.
I’m using WP 3.9.2 and the Genesis framework, if that is an important fact.
Do you have any idea what this may be due?
It appears directly above the “Appearance” menu item for me. If I change the menu_position param (https://github.com/devinsays/team-post-type/blob/master/includes/class-post-type-registrations.php#L69) it updates. Perhaps there is something specific with Genesis, have you tested it with a different theme?
Hi Devin,
You were right! It is something specific with Genesis. Tested with WP default themes and it works perfect.
Thank you for the code. Easy to follow. I’m working on a project that requiered cusom post and taxonomies. In the past we would use a plugin to handle that, however we moving to a more custom design. So integrating this into our theme or plugin will be extremly beneficial.
How i could for an example I make below facebook url another custom field which would be an image uploader, so i could add there some specific image (not featured image and not post thumb), like a small logo?
I am trying to do this for a few days, and i manage to add upload button there but it doesnt pop up.
Any suggestions?