Support

Account

Home Forums Backend Issues (wp-admin) Using ACF to create CPT in back-end Reply To: Using ACF to create CPT in back-end

  • Ok, try this, I changed the location of the add_action hook and changed “movie” texts with $cpt_name

    
    if( have_rows('additional-post-type', 'option') ):
        function custom_post_type() {
            while ( have_rows('additional-post-type', 'option') ) : the_row();
         
            $cpt_name = get_sub_field('cpt-name');
            $cpt_slug = slugify($cpt_name);
    
            register_post_type( $cpt_slug , array(
                'label'               => __( $cpt_slug, 'twentythirteen' ),
                'description'         => __( $cpt_slug.' news and reviews', 'twentythirteen' ),
                'labels'              => array(
                        'name'                => _x( $cpt_name, 'Post Type General Name', 'twentythirteen' ),
                        'singular_name'       => _x( $cpt_name, 'Post Type Singular Name', 'twentythirteen' ),
                        'menu_name'           => __( $cpt_name, 'twentythirteen' ),
                        'parent_item_colon'   => __( 'Parent '.$cpt_name, 'twentythirteen' ),
                        'all_items'           => __( 'All '.$cpt_name, 'twentythirteen' ),
                        'view_item'           => __( 'View '.$cpt_name, 'twentythirteen' ),
                        'add_new_item'        => __( 'Add New '.$cpt_name, 'twentythirteen' ),
                        'add_new'             => __( 'Add New', 'twentythirteen' ),
                        'edit_item'           => __( 'Edit '.$cpt_name, 'twentythirteen' ),
                        'update_item'         => __( 'Update '.$cpt_name, 'twentythirteen' ),
                        'search_items'        => __( 'Search '.$cpt_name, 'twentythirteen' ),
                        'not_found'           => __( 'Not Found', 'twentythirteen' ),
                        'not_found_in_trash'  => __( 'Not found in Trash', 'twentythirteen' ),
                    ),
                'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
                'hierarchical'        => false,
                'public'              => true,
                'show_in_nav_menus'   => true,
                'show_in_admin_bar'   => true,
                'menu_position'       => 5,
                'can_export'          => true,
                'has_archive'         => true,
                'exclude_from_search' => false,
                'publicly_queryable'  => true,
                'capability_type'     => 'page',
                )
            );
         
            endwhile;
        }
        
        add_action( 'init', 'custom_post_type', 0 );
    endif;