Custom Post Type creation with Advanced Custom Fields WITHOUT the use of an additional plugin.

[ad_1]

Hello!

I’m currently trying to integrate my own Custom Post Type generator into a WordPress theme I’m building. I’m aware of additional plugins such as CPT UI or ACF Extended, but I’d much prefer to build something simple myself to cut down on the number of plugins required.

I’ve currently put together the following code using ACF repeater fields in a separate PHP file that is called through as ‘required’ in my functions.php file, but it doesn’t seem to be working and I can’t understand why:

[https://pastebin.com/fjzScrjg])

I’ve created $variables for each of my get\_field requests as I was under the impression that trying to call ACF fields as they are directly within quote marks wouldn’t work, but if there’s a way around this that would be great.

For reference, pretty much all of these fields being called are standard ACF text fields.

I understand that there are a lot more fields that will need to be called (taxonomies for example), but for now, I want to focus on getting the core structure working and I can worry about building on this afterwards.

If anyone could point me in the right direction by letting me know if I’m missing something obvious it would be very much appreciated!

[ad_2]
1 Comment
  1. The file start off with `get_sub_field` – you need to be in a Repeater loop to use that. So move all that code into your `have_rows` loop.

    Quotes don’t go around variables. e.g. `”$cpt_slug”` is incorrect.

 

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