Register post type without init
-
So I am trying to create a new post type but the only way I can get it to work is if I use the action ‘init’. But the problem is I want this post type to be created when I submit a form. The code I am using is below.
// Our custom post type function
function create_posttype() {
$name = ‘animal’;
$singular = ucfirst($name);
$plural = $singular;
$plural.= ‘s’;
$name = lcfirst($plural);register_post_type( $name,
// CPT Options
array(
‘labels’ => array(
‘name’ => __( $plural ),
‘singular_name’ => __( $singular )
),
‘public’ => true,
‘has_archive’ => false,
‘show_in_rest’ => true,)
);
}
// Hooking up our function to theme setup
add_action( ‘init’, ‘create_posttype’ );
`
- The topic ‘Register post type without init’ is closed to new replies.