Part 1: How to add Custom Fields to a Custom Post Type using the Advanced Custom Fields (ACF) WordPress Plugin

In a previous tutorial we’ve talked about the Advanced Custom Fields (ACF) WordPress plugin and how to hide the settings unless the user is an admin. Now we are bringing you another two-part tutorial revolving around this powerful plugin. You may already know how to add the ACF custom option pages to the WordPress dashboard so now we are going to teach you how to take them a step further by adding them directly to a custom post type. In part 1 of this two-part tutorial, we are going to teach you how to add custom fields to a custom post type using the Advanced Custom Fields (ACF) WordPress plugin and a PHP function.

Step 1: Setup and Attach the Advanced Custom Fields (ACF) Options Page to a Custom Post Type via a PHP Function

In order to add an Advanced Custom Fields (ACF) Options Page to your custom post type in the WordPress dashboard we will need to add a PHP filter to the WordPress functions file. Simply open your functions.php file then copy and paste the code below, please refer to the ‘Items to Note’ below for detailed setup instructions.

PHP

if( function_exists('acf_add_options_page') ) {
	acf_add_options_sub_page(array(
		'page_title' 	=> 'YOUR-PAGE-TITLE',
		'menu_title'	=> 'YOUR-MENU-TITLE',
		'menu_slug' 	=> 'site-options-YOUR-SLUG',
		'capability'	=> 'edit_posts',
		'parent_slug'	=> 'edit.php?post_type=YOUR-CUSTOM-POST-TYPE',
	));
}

Items to Note:

  • Make sure that you change where it says ‘YOUR-PAGE-TITLE’ to a custom page title of your choice.
  • Make sure that you change where it says ‘YOUR-MENU-TITLE’ to a custom menu title of your choice.
  • Make sure that you change where it says ‘YOUR-SLUG’ to a custom slug of your choice.
  • Make sure that you change where it says ‘YOUR-CUSTOM-POST-TYPE’ to the custom post type that you want to add your custom fields option page to.

Step 2: Create the Advanced Custom Fields (ACF) Field Group in the WordPress Dashboard to attach to your Custom Post Type’s Options Page

After creating your ACF Options Page for your Custom Post Type in Step 1, the next step is to create the Field Group with the ACF Plugin settings panel in the WordPress Dashboard and then attach it to your Post Type’s Options Page. Follow the step by step instructions below:

  1. Log in to the dashboard of your WordPress site
  2. Go to Custom Fields -> Add New
  3. Title your Field Group
  4. Add your desired custom fields
  5. Go to the Locations panel -> Show this field group if -> Select ‘Options Page’ -> Select ‘is equal to’ -> Select your options page
  6. Publish

After completing the above steps your newly create ACF Field Group should now be attached to your Custom Post Type’s Options Page.

PART 2: How to Display the Advanced Custom Fields (ACF) for your Custom Post Type in the WordPress Theme Template File

In part 2 of this tutorial we will teach you how to display the custom fields you created for your Custom Post Type in your WordPress theme template file using PHP.

View Part 2

Troubleshooting

If you are having problems getting this tutorial to work please reread the tutorial and try again, if you still cannot get it to work please leave us a comment below and we will respond as soon as possible. Please do not email us with problems regarding this tutorial, only comments will be responded to.