v3
This documentation for the Custom post types plugin for WordPress allows you to customize all features.
To get professional support you need to make a donation to get the PRO version of the plugin.
Old version of this awesome plugin.
Create post type & taxonomy
Create custom fields
Create custom template
Post types hooks
Manipulate the labels:
add_filter("cpt_register_labels_{POST-TYPE-ID}", function($labels){
//
// manipulates the $labels
//
return $labels;
});
Manipulate the args:
add_filter("cpt_register_args_{POST-TYPE-ID}", function($args){
//
// manipulates the $args
//
return $args;
});
For details on on this manipulation, visit the official WordPress documentation.
Taxonomies hooks
Manipulate the labels:
add_filter("cpt_register_tax_labels_{TAX-ID}", function($labels){
//
// manipulates the $labels
//
return $labels;
});
Manipulate the args:
add_filter("cpt_register_tax_args_{TAX-ID}", function($args){
//
// manipulates the $args
//
return $args;
});
For details on on this manipulation, visit the official WordPress documentation.
Fields hooks
Add custom field support:
add_filter('cpt_available_fields', function ($available_fields) {
$available_fields['text'] = [
'label' => __('Text', 'custom-post-types'),
'fields' => [ // extra fields
[
'key' => 'placeholder',
'label' => __('Placeholder', 'custom-post-types'),
'info' => false,
'required' => false,
'type' => 'text',
'extra' => [],
'wrap' => [
'width' => '',
'class' => '',
'id' => '',
'layout' => ''
]
],
]
];
return $available_fields;
});
In the example above the “text” field type support is added.
Manipulate the output of a custom field by type:
add_filter("cpt_get_field_type_{FIELD-TYPE}", function($output, $value, $post_type, $post_id){
//
// manipulates the $output
//
return $output;
}, 10, 4);
Manipulate the output of a custom field by id:
add_filter("cpt_get_field_{FIELD-ID}", function($output, $value, $post_type, $post_id){
//
// manipulates the $output
//
return $output;
}, 10, 4);
Manipulate the entered value of the custom field before saving:
add_filter("cpt_sanitize_field_{FIELD-TYPE}", function($input){
//
// manipulates the $input
//
return $input;
});
Templates hooks
Add blank template support to wrap type for your theme:
add_filter('cpt_themes_supports_rules', function ($supports_rules) {
$supports_rules['twentytwenty'] = [
'file-name' => 'singular.php',
'replace-callback' => function ($content_to_replace) {
$content_to_replace = str_replace("get_template_part( 'template-parts/content', get_post_type() )", 'custom_post_types_get_custom_template()', $content_to_replace);
return $content_to_replace;
},
];
return $supports_rules;
});
In the example above the “Twenty Twenty” theme support is added, the necessary data are: theme folder name, path to the single template (file-name), callback to replace the default loop with the plugin function (replace-callback).
Settings fields
To avoid overwriting important settings that could damage your website database, the custom fields on the settings pages are stored by adding a suffix to the key.
For example, if you have created a field in the “Settings > General” page using the “text_field” key, you can retrieve that value using:
$field_value = get_option('general-text_field');
The prefixes to use based on where the custom field group has been assigned:
- general–
- writing-
- reading-
- discussion-
- media-