posttypes.json

This file, as you might expect, is responsible for registering custom post types.

Defaults

PorterWP has a set of defaults for post type creation, which makes the processing of registering new post types very clean. The default settings are:

[
    'public' => true,
    'show_in_rest' => true,
    'supports' => [
        'title', 
        'editor', 
        'thumbnail', 
        'excerpt', 
        'custom-fields', 
        'revisions'
    ],
]

You can filter these default values by using the filter porter_default_object_args where the $group is "posttype"

$args = apply_filters( 'porter_default_object_args', $args, $group );

See for more information.

Register new post type

Registering a new post type is as easy as adding a new item to the post types object.

For example, adding an event would look like this:

{
	"version" : "1.0.0",
	"posttypes" : {
		"event" : {}
	}
}

ALWAYS use singular names for posttype registration. Not just in PorterWP, but always.

e.g. event not events

PorterWP will attempt to generate servicable labels, but you can override them if you'd prefer to define your own labels.

For example the plural of Research is Research, not Researchs (which is what PorterWP would generate by default). So if you were registering a posttype called "research" you would do the following:

...
	"research" : {
		"labels" : {
			"singular_name" : "Research",
			"name" : "Research"
		}	
	}
...

You can of course set any other params from from register_post_type function here, too. (ref: https://developer.wordpress.org/reference/functions/register_post_type/)

For example:

...
	"video" : {
		"exclude_from_search" : true,
		"taxonomies" : [ "category" ],
	}
...

If you need to adjust the "supports" options from the default settings, you must include ALL supported elements. PorterWP will assume you don't want to use the default "supports" settings.

Last updated