• 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’ );
    `

    • This topic was modified 4 years, 2 months ago by lex713.
Viewing 1 replies (of 1 total)
  • Don’t equate registering a post type with creating a post of that type.
    You need to register the post type each time WordPress is loaded.
    You would want to create a post when a form is submitted (is that right?).
    WordPress registers the Post type and the Page type (standard types) each time it is loaded. You do the same for custom types.

Viewing 1 replies (of 1 total)
  • The topic ‘Register post type without init’ is closed to new replies.