On this page
- Category: Getting Started
- Written: December 11, 2011
- Updated: December 13, 2011
Creating a Field Group
ACF uses Field groups to attach fields to posts. Each Field group can contain multiple fields and can be assigned to multiple posts via the location rules. To create your first field group, Click on Setting -> Adv Custom Fields. You should see a screen like this:
Clicking the “Add New” button will create a Field Group. When editing a field group, you will see 3 main areas of interest. These are:
Each field group requires a title. This title is shown in the metabox handle on the edit screen. A good tip is to use relevant titles such as “Home Page” or “Event”
Here you can create and manage a variety of custom fields. Clicking the “Add Field” button will create a new field and add it to the bottom of the list (you can reorder your fields by dragging the order number as a handle). Adding a field will look like this:
Each field requires a Label, name and type. All other options are not required and are will change depending on the field type.
The field label is visible when entering content but is not used by the API, use capitals and spaces for a human friendly field label.
The field name is the computer version which should be lowercase and have no spaces / special characters. This name is used in your templates to retrieve the content / data.
Hovering over the grey bar at the top of the field will reveal action buttons similar to any other WP list. These actions allow you to delete, edit (open / close) and link to the documentation (handy!)
The location box allows you to create a set of rules to decide when and where to add these fields to the edit screen / post object. It has been based of the itunes playlist editor and 9 times out of 10 will give you all the options you need to add your field group to a post / page, custom post type, custom template, etc. Here is an example of some location rules which will make this field group appear only on pages where the template chosen is “Sidebar Template”
Please be sure ti think about the “All or Any” selection as this can drastically alter where your field group appears. Choosing “All” means all the above location rules must be met for this field group to appear. Choosing “Any” means any of the location rules must be true for the field group to appear.
Most of the time, the “All” option is what you want. For the programmers, “all” = “&&” (and), “any” == “||” (or).
For each field group, there are a few simple options to help customize the edit screen where this field group appears. If you have multiple field groups appearing on a page, the first field group’s options will be used. This is why you can set a order number. Field groups are loaded and displayed in order of their “order no” where 0 is the first and 99 is the last.