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' );
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.