Is it possible to call ACF fields as variables inside a register_post_type repeater field loop?

This is a follow-up post to [a recent thread I made last week]), where I asked whether it was possible to create custom post types using Advanced Custom Fields without the use of an additional plugin.

Since my original post, I have moved my variable definitions into the while loop at the suggestion of /u/bluesix, and have done some A/B testing which reveals that none of the custom variables I’ve defined [in my latest code]) below seem to be pulling through at all.

For example, changing the contents of the `$cpt_slug` variable to output a simple `“post-type-name”` string (instead of pulling through any ACF field data) results in the CPT not registering, but typing the exact same `“post-type-name”` string into the `register_post_type` action directly as shown below, *does* register the CPT (albeit without any of the custom labels I’m trying to get working):

`register_post_type( “post-type-name”, $args );`

I don’t understand why the default `$args` variable shown above is able to pull through array data just fine, but any variables that I try and define don’t pull through at all.

Additionally, the if / else statements defined for the `$labels` arrays aren’t working properly either. I know this because changing all of the `$args` lines to be written in their standard format (without any variable or ACF field calls at all) results in the default `else:` variations I’ve defined pulling through instead.

I support the heart of my questions is, **does anybody know why any of the variables I’ve defined earlier in the code aren’t pulling through at all, and if this isn’t possible, what edits can I make to the code to ensure I can use ACF fields to register custom post types?**

Thank you in advance for your help as this has been bugging me for a few days now!

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer