Field Group

Field Group

Settings

The FieldGroup class accepts a title, and optional name and key overrides.

use JorenRothman\ACFBuilder\FieldGroup;
 
$fieldGroup = new FieldGroup('My Field Group');

The following settings can be configured via setter methods:

MethodDefaultOptions
setPosition(string)'normal''normal', 'side', 'acf_after_title'
setStyle(string)'default''default', 'seamless'
setLabelPlacement(string)'top''top', 'left'
setInstructionPlacement(string)'label''label', 'field'
setMenuOrder(int)0Any integer
setActive(bool)truetrue, false
setDescription(string)''Any string
setShowInRest(bool)falsetrue, false
setHideOnScreen(array)''See below

Hide on Screen

Pass an array of UI elements to hide from the WordPress edit screen:

$fieldGroup->setHideOnScreen([
    'permalink',
    'the_content',
    'excerpt',
    'discussion',
    'comments',
    'revisions',
    'slug',
    'author',
    'format',
    'page_attributes',
    'featured_image',
    'categories',
    'tags',
    'send-trackbacks',
]);

Example

use JorenRothman\ACFBuilder\FieldGroup;
 
$fieldGroup = new FieldGroup('My Field Group');
$fieldGroup
    ->setPosition('side')
    ->setStyle('seamless')
    ->setLabelPlacement('top')
    ->setDescription('Fields for my custom post type');

Locations

FieldGroupLocations controls where a field group appears in the WordPress admin.

and()

Adds a rule to the current location group (all rules in a group must match — AND logic).

or()

Adds a rule to a new location group (any group can match — OR logic).

use JorenRothman\ACFBuilder\FieldGroupLocations;
 
$locations = new FieldGroupLocations();
 
// Show on pages OR posts
$locations
    ->and('post_type', '==', 'page')
    ->or('post_type', '==', 'post');

Location Parameters

ParameterDescription
post_typePost type slug
post_templatePage template filename
post_statusPost status
post_formatPost format
post_categoryPost category
post_taxonomyPost taxonomy term
postSpecific post
page_templatePage template
page_typePage type (front page, posts page, etc.)
page_parentPage parent
pageSpecific page
current_userCurrent logged-in user
current_user_roleCurrent user role
user_formUser form (add/edit)
user_roleUser role
taxonomyTaxonomy edit screen
attachmentMedia attachment
commentComment
widgetWidget
nav_menuNavigation menu
nav_menu_itemNavigation menu item
blockGutenberg block
options_pageACF options page

Operators

OperatorDescription
==Equal to
!=Not equal to

Registering with Locations

You can pass locations directly to register():

use JorenRothman\ACFBuilder\FieldGroup;
use JorenRothman\ACFBuilder\Fields\Basic\Text;
use JorenRothman\ACFBuilder\FieldGroupLocations;
 
$fieldGroup = new FieldGroup('My Field Group');
$fieldGroup->addField(Text::make('My Text Field'));
 
$locations = new FieldGroupLocations();
$locations->and('post_type', '==', 'page');
 
$fieldGroup->register($locations);