In our previous tutorial on how to create a field groups using ACPT, we learned two methods of creating field groups. In this tutorial, we will explore how to assign those field groups to a specific post or CPT.
Assigning Field Group to a CPT
To assign field groups to a CPT or pages, posts, users, or taxonomy, the first step is to set the location for those field groups. This involves defining the conditions that determine where the fields will be displayed.
In the field groups settings, you will find an “Add Condition” button. Click on this button to add your first condition for the field group.
After clicking the “Add Condition” button, you will see three dropdown menus that will help you determine where to display the field groups.
- Location Dropdown: This dropdown allows you to select the type of content where the field group will appear. Options include posts, taxonomies, attachments, users, and options pages.
- Condition Dropdown: The second dropdown lets you specify the logic for the condition. Options include:
- “is equal to”
- “is not equal to”
- “is included in”
- “is not included in”
- Value Dropdown: The final dropdown is for selecting the specific post, page, or item related to the location you defined. The values available here will depend on the location you selected, as the options will vary based on the chosen content type.
By choosing your options from these dropdowns, you can customize exactly where and how your field groups will be displayed based on the specific conditions you set.
In this tutorial, we aim to display our field groups in the Recipes Custom Post Type. To do this, we will select the location option of “Post Type.”
We will set the condition to “is equal to,” ensuring that the field groups will only be displayed when the post type matches the value, which is the Recipe Custom Post Type.
Once you have assigned your field groups to a specific location, click on “Save,” and you’re all set!
After saving, you will be redirected to the field group overview page, where you can view the newly created field groups. This information includes the group name, the location of the field group, and the number of fields. We will explore the other options as we delve deeper into custom fields.
In our next tutorial, we will focus on creating meta boxes and fields. This will allow us to explore the functionalities of custom post types in greater depth, enhancing our ability to customize and manage our content effectively.