I am not finding any information regarding registering a CPT. I’ve seen discussion about registering them as a plugin, but previously I would just register them in function.php.
Is there any other documentation anywhere? Coming from Laravel where the documentation is very detailed I feel that there is a considerable lack of information.
I can’t seem to find any information about how to add CPT as a plugin.
I am confused? Wordpress.org says to register it in the theme, but i’ve read else where on here to add them as a plugin… If “Registering custom post types is kind of beyond the scope of Sage” where and how do you register them.
Is there some documentation about this? Is it in the paid download?
Sorry for all the questions, it is really hard trying to find the solution amongst a variety of obscure answers online.
Registering CPT in theme / plugin is totally up to you and depends on the context. Extract it out into a plugin if it’s not theme specific or will be shared across different sites. Pop it in the theme if it’s theme specific. I’d start in theme and extract out to a plugin later if you need to, no point adding extra boilerplate code early on!
Then within your ‘app’ folder, register a php file eg. cpt-team.php and here is example code to register a ‘Team’ custom post type with roles taxonomy:
We put the CPT definitions and other information architecture things like taxonomies in a mu-plugin. The idea is that if the client later wants to switch to a different theme, the IA would still be required.
But lately I’ve started to see the whole project as a singular app and the theme and IA are too intertwined to really tease apart cleanly. So I’m leaning towards migrating the IA stuff into the theme.
It’s really a matter of personal preference, though if you do go with a mu-plugin you have to add additional steps in any deploy script you write.
Personally I create a custom-post-types.php file in the app folder, where I place the cpt declaration (using the johnbillion/extended-cpts plugin syntax)
In order to have the custom-post-types.php loaded, I am changing the “Sage required files” in functions php ( line 61 for me ) : ['helpers', 'setup', 'filters', 'admin', 'custom-post-types', 'acf']