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

  • You’re welcome!

    I tried with your code and didn’t work for me too, so I did a few changes and now works for me.
    In this code I use a function called slugify (https://stackoverflow.com/questions/2955251/php-function-to-make-slug-url-string), to create the CPT slug.

    Tell me if it works for you

    
    if( have_rows('additional-post-type', 'option') ) {
    
        function register_post_types() {
    
           while ( have_rows('additional-post-type', 'option') ) { the_row();
    
                $cpt_name = get_sub_field('cpt-name');
                $cpt_slug = slugify($cpt_name);
    
                // new custom post type
                register_post_type(
                    $cpt_slug , array(
                        'public' => true,
                        'labels' => array(
                            'name' => __($cpt_name, 'theme'),
                            'singular_name' => __($cpt_name, 'theme'),
                        ),
                        'has_archive' => true,
                        'supports' => array(
                            'title',
                            'thumbnail',
                        ),
                    )
                );
            }
    
        }
    
        add_action( 'init', 'register_post_types' );
    }