An Advanced Custom Fields helper for WordPlate.
Require this package, with Composer, in the root directory of your project.
$ composer require wordplate/acf
Use the acf_field_group()
helper function to register a new field group in ACF. It uses the acf_add_local_field_group()
function behind the scenes. The difference is that it appends the key
value to all fields keys. Below you'll find an example of a field group below.
$fields = [
acf_image(['name' => 'image', 'label' => 'Image']),
acf_text(['name' => 'title', 'label' => 'Title']),
];
$location = [
acf_location('post_type', 'post'),
acf_location('post_type', '!=', 'page'),
];
acf_field_group([
'title' => 'About',
'key' => 'about',
'fields' => $fields,
'location' => [
$location
],
]);
Visit the official documentation to read more about the field group settings.
All fields accepts an array of settings. All field settings arrays must have the keys label
and name
. Below the example you'll find a list of available field functions.
acf_text([
'label' => 'Field Label'
'name' => 'unique-field-name'
]);
Below you'll find a list of settings and their descriptions you can add to your fields. Visit the official documentation to read more about the field settings.
Name | Description |
---|---|
label |
This is the label which appears on the edit page when entering a value. |
name |
This is the name used to save and load data from the database. This name must be a single word, no spaces, underscores and dashes allowed. |
type |
The type of field will change the settings available, the interface when entering data, and the value returned from the database. |
instructions |
This text appears on the edit page when entering a value. |
required |
Required fields will cause validation to run when saving a post. When attempting to save an empty value to a required field, an error message will display. |
conditional_logic |
Once enabled, more settings will appear to customize the logic which determines if the current field should be visible or not. Groups of conditional logic can be created to allow for multiple and/or statements. The available toggle fields are limited to those which are of the type select, checkbox, true/false, radio. |
acf_text()
- The text field creates a simple text input.acf_textarea()
- The textarea field creates a simple textarea.acf_number()
- The number field creates a simple number input.acf_email()
- The email field creates a simple email input.acf_url()
- The url field creates a simple url input.acf_password()
- The password field creates a simple password input.
acf_checkbox()
- The checkbox field creates a list of tick-able inputs.acf_radio()
- The radio button field creates a list of select-able inputs.acf_select()
- The select field creates a drop down select or multiple select input.acf_true_false()
- The true / false field allows you to select a value that is either 1 or 0.
acf_file()
- The file field allows a file to be uploaded and selected.acf_gallery()
- The gallery field provides a simple and intuitive interface for managingacf_image()
- The image field allows an image to be uploaded and selected.acf_oembed()
- The oEmbed field allows an easy way to embed videos, images, tweets, audio, and other content.acf_wysiwyg()
- The WYSIWYG field creates a full WordPress tinyMCE content editor.
acf_color_picker()
- The color picker field allows a color to be selected via a JavaScript popup.acf_date_picker()
- The date picker field creates a jQuery date selection popup.acf_date_time_picker()
- The date time picker field creates a jQuery date & time selection popup.acf_google_map()
- The Google Map field creates an interactive map with the ability to place a marker.acf_time_picker()
- The time picker field creates a jQuery time selection popup.
acf_clone()
- The clone field allows you to select and display existing fields.acf_flexible_content()
- The flexible content field acts as a blank canvas to which you can add an unlimited number of layouts with full control over the order.acf_group()
- The group allows you to create a group of sub fields.acf_message()
- The message fields allows you to display a text message.acf_repeater()
- The repeater field allows you to create a set of sub fields which can be repeated again and again whilst editing content!acf_tab()
- The tab field is used to group together fields into tabbed sections.
acf_link()
- The page link field provides a simple way to select or define a link (url, title, target).acf_page_link()
- The page link field allows the selection of 1 or more posts, pages or custom post types.acf_post_object()
- The post object field creates a select field where the choices are your pages + posts + custom post types.acf_relationship()
- The relationship field creates a very attractive version of the post object field.acf_taxonomy()
- The taxonomy field allows the selection of 1 or more taxonomy terms.acf_user()
- The user field creates a select field for all your users.
This package provides three helper packages acf_conditional_logic()
and acf_location()
to help you write less arrays for your field groups.
The acf_conditional_logic()
function help you write conditional logic without knowing the fields key
value.
acf_conditional_logic('type', 'image');
acf_conditional_logic('type', '!==' 'image');
The acf_location()
function help you write location
arrays without the name
, operator
and value
keys.
acf_location('post_type', 'post');
acf_location('post_type', '!=', 'post');