Menü schliessen
Created: May 1st 2020
Last updated: May 1st 2020
Categories: IT Development
Author: Marcus Fleuti

Basic use of the ACF Wordpress plugin - Advanced Custom Fields

Donation Section: Background
Monero Badge: QR-Code
Monero Badge: Logo Icon Donate with Monero Badge: Logo Text
82uymVXLkvVbB4c4JpTd1tYm1yj1cKPKR2wqmw3XF8YXKTmY7JrTriP4pVwp2EJYBnCFdXhLq4zfFA6ic7VAWCFX5wfQbCC

Introduction

This post will explain you how to use acf to create custom back-end page. Acf enables to create very flexible template for a page.

ACF enables you to create many types of fields which are grouped in six groups(Basic, Content, Choice, Relational, Jquery, Layout).

We can create tabs, groups, repeaters and other layouts which constists of some types of fields from the rest of the groups. When we created fields, we made sure that item's id(Field Name) isn't the same like id of some other field. To get information from the field we use function get_field("field_name"[,"option"]). Argument "option" is optional, and we use it when we get information from the field from Team option template(Team option constist common information for every page).

When we want to take information from some group's field, we have to take group, like array of subfields with function get_field("name_of_group") and save that in some variable. That variable is associative array of subfields from that group and we get information like this:

var group = get_field("name_of_group");
var first_subfield = group["name_of_first_field"];

Repeaters

Repeater is very important field and it enables us to create something like loop in programming. Repeater consists of subfields like a group, but repeater enables us to create multiple groups of the same type. When we want to take information from some repeater's field, we have to take repeater field like array of more the same group. We get repeater with the same function like other fields

var repeater = get_fields("name_of_repeater");
var first_group = repeater[0];

We need to use loop(for, foreach, while) to get all of the fields from the repater like this:

foreach(repeater as group)
{
var first_field_in_group = group["field_name"];
/* ... */
}

We have more options to adjust fields. The field's width, class and id can be adjusted. The field can be required. Also we can limit the number of characters in the field, to set default value for some fields and more other options. Another very important option is that we can adjust conditional logic for some fields.
If conditional logic button is active, we can adjust logic when we can show that field.

Some options are, when another field: "has any value", "has no value", "value match pattern, "value contens value". And we can choose tamplate where we want to show or template where we won't show that field.