Fields
All fields extend the base Field class and share these common methods:
| Method | Description |
|---|---|
setRequired(bool) | Mark the field as required |
setInstructions(string) | Add helper text shown below the label |
setWrapper(string $width, string $class, string $id) | Set the HTML wrapper attributes |
setConditionalLogic(FieldConditionalLogic) | Show/hide the field based on other fields |
Fields can be created with new or with the static ::make() factory for cleaner chaining:
Text::make('My Text Field')->setRequired(true)->setInstructions('Enter some text');Basic Fields
Text
use JorenRothman\ACFBuilder\Fields\Basic\Text;
$text = Text::make('Text Field');Textarea
use JorenRothman\ACFBuilder\Fields\Basic\Textarea;
$textarea = Textarea::make('Textarea Field')
->setNewLines('wpautop'); // 'wpautop', 'br', ''Number
use JorenRothman\ACFBuilder\Fields\Basic\Number;
$number = Number::make('Number Field');Range
use JorenRothman\ACFBuilder\Fields\Basic\Range;
$range = Range::make('Range Field');use JorenRothman\ACFBuilder\Fields\Basic\Email;
$email = Email::make('Email Field');URL
use JorenRothman\ACFBuilder\Fields\Basic\URL;
$url = URL::make('URL Field');Password
use JorenRothman\ACFBuilder\Fields\Basic\Password;
$password = Password::make('Password Field');Content Fields
Image
use JorenRothman\ACFBuilder\Fields\Content\Image;
$image = Image::make('Image Field')
->setReturnFormat('array') // 'array', 'url', 'id'
->setPreviewSize('medium') // 'thumbnail', 'medium', 'large', 'full'
->setLibrary('all'); // 'all', 'uploadedTo'Gallery
use JorenRothman\ACFBuilder\Fields\Content\Gallery;
$gallery = Gallery::make('Gallery Field')
->setPreviewSize('thumbnail') // 'thumbnail', 'medium', 'large', 'full'
->setLibrary('all'); // 'all', 'uploadedTo'File
use JorenRothman\ACFBuilder\Fields\Content\File;
$file = File::make('File Field')
->setReturnFormat('array') // 'array', 'url', 'id'
->setPreviewSize('thumbnail') // 'thumbnail', 'medium', 'large', 'full'
->setLibrary('all'); // 'all', 'uploadedTo'Wysiwyg
use JorenRothman\ACFBuilder\Fields\Content\Wysiwyg;
$wysiwyg = Wysiwyg::make('Wysiwyg Field')
->setTabs('all') // 'all', 'visual', 'text'
->setToolbar('full'); // 'full', 'basic'OEmbed
use JorenRothman\ACFBuilder\Fields\Content\OEmbed;
$oembed = OEmbed::make('OEmbed Field');Choice Fields
Select
use JorenRothman\ACFBuilder\Fields\Choice\Select;
$select = Select::make('Select Field')
->setChoices(['draft' => 'Draft', 'published' => 'Published'])
->setReturnFormat('value'); // 'value', 'label', 'array'Checkbox
use JorenRothman\ACFBuilder\Fields\Choice\Checkbox;
$checkbox = Checkbox::make('Checkbox Field')
->setChoices(['option_a' => 'Option A', 'option_b' => 'Option B'])
->setLayout('vertical') // 'vertical', 'horizontal'
->setReturnFormat('value'); // 'value', 'label', 'array'Radio Button
use JorenRothman\ACFBuilder\Fields\Choice\RadioButton;
$radio = RadioButton::make('Radio Field')
->setChoices(['option_a' => 'Option A', 'option_b' => 'Option B'])
->setLayout('vertical') // 'vertical', 'horizontal'
->setReturnFormat('value'); // 'value', 'label'Button Group
use JorenRothman\ACFBuilder\Fields\Choice\ButtonGroup;
$buttonGroup = ButtonGroup::make('Button Group Field')
->setChoices(['option_a' => 'Option A', 'option_b' => 'Option B'])
->setLayout('horizontal'); // 'vertical', 'horizontal'True False
use JorenRothman\ACFBuilder\Fields\Choice\TrueFalse;
$trueFalse = TrueFalse::make('True False Field')
->setUI(true)
->setUiOnText('Yes')
->setUiOffText('No');Relational Fields
Link
use JorenRothman\ACFBuilder\Fields\Relational\Link;
$link = Link::make('Link Field')
->setReturnFormat('array'); // 'array', 'url'Post Object
use JorenRothman\ACFBuilder\Fields\Relational\PostObject;
$postObject = PostObject::make('Post Object Field')
->addPostType('post')
->setReturnFormat('object'); // 'object', 'id'Page Link
use JorenRothman\ACFBuilder\Fields\Relational\PageLink;
$pageLink = PageLink::make('Page Link Field')
->addPostType('page')
->setAllowNull(false);Relationship
use JorenRothman\ACFBuilder\Fields\Relational\Relationship;
$relationship = Relationship::make('Relationship Field')
->addPostType('post', 'page')
->setReturnFormat('object'); // 'object', 'id'Taxonomy
use JorenRothman\ACFBuilder\Fields\Relational\Taxonomy;
$taxonomy = Taxonomy::make('Taxonomy Field')
->setTaxonomy('category')
->setFieldType('checkbox') // 'checkbox', 'multi_select', 'select', 'radio'
->setReturnFormat('object'); // 'id', 'object'User
use JorenRothman\ACFBuilder\Fields\Relational\User;
$user = User::make('User Field')
->setReturnFormat('object'); // 'array', 'object', 'id'Layout Fields
Message
use JorenRothman\ACFBuilder\Fields\Layout\Message;
$message = Message::make('Message Field')
->setMessage('This is a message.')
->setNewLines('wpautop'); // 'wpautop', 'br', ''Group
use JorenRothman\ACFBuilder\Fields\Layout\Group;
$group = Group::make('Group Field')
->setLayout('block') // 'row', 'column', 'block'
->addSubField(Text::make('Sub Text'));Repeater
use JorenRothman\ACFBuilder\Fields\Layout\Repeater;
$repeater = Repeater::make('Repeater Field')
->setLayout('block') // 'table', 'row', 'block'
->setButtonLabel('Add Row')
->addSubField(Text::make('Sub Text'));Flexible Content
use JorenRothman\ACFBuilder\Fields\Layout\FlexibleContent;
use JorenRothman\ACFBuilder\Fields\Layout\FlexibleLayout;
$layout = new FlexibleLayout('Text Layout');
$layout->addSubField(Text::make('Content'));
$flexibleContent = FlexibleContent::make('Flexible Content Field')
->addLayout($layout);Accordion
use JorenRothman\ACFBuilder\Fields\Layout\Accordion;
$accordion = Accordion::make('Accordion Field')
->setOpen(false)
->setMultiExpand(false)
->setEndpoint(false);Tab
use JorenRothman\ACFBuilder\Fields\Layout\Tab;
$tab = Tab::make('Tab Field')
->setPlacement('top'); // 'top', 'left'jQuery Fields
Google Map
use JorenRothman\ACFBuilder\Fields\JQuery\GoogleMap;
$googleMap = GoogleMap::make('Google Map Field');Date Picker
use JorenRothman\ACFBuilder\Fields\JQuery\DatePicker;
$datePicker = DatePicker::make('Date Picker Field')
->setDisplayFormat('d/m/Y')
->setReturnFormat('d/m/Y')
->setFirstDay('monday'); // 'sunday', 'monday', ..., 'saturday'Date Time Picker
use JorenRothman\ACFBuilder\Fields\JQuery\DateTimePicker;
$dateTimePicker = DateTimePicker::make('Date Time Picker Field')
->setDisplayFormat('d/m/Y g:i a')
->setReturnFormat('d/m/Y g:i a')
->setFirstDay('monday'); // 'sunday', 'monday', ..., 'saturday'Time Picker
use JorenRothman\ACFBuilder\Fields\JQuery\TimePicker;
$timePicker = TimePicker::make('Time Picker Field')
->setDisplayFormat('g:i a')
->setReturnFormat('g:i a');Color Picker
use JorenRothman\ACFBuilder\Fields\JQuery\ColorPicker;
$colorPicker = ColorPicker::make('Color Picker Field')
->setReturnFormat('string') // 'string', 'array'
->setEnableOpacity(false);