A set of PHP classes and methods to assist with ACF. Enables a straight forward way of working with ACF fields by providing a simple, clean and self describing intererface.
All methods are static and can be called directly from the class name from anywhere in the code.
The libary adds functionality to get the visibility state of a field and also provides a way to get the completeness amount of all fields in a field group based on the visibility state and the amount of filled fields by the user.
ACF Helper | ACF |
---|---|
Field::setKey('field_xxxxx')::get(); |
get_field_object('field_xxxxx'); |
Field::setKey('field_xxxxx')::get('label'); |
get_field_object('field_xxxxx')['label']; |
Field::setKey('field_xxxxx')::setUserId(2458)::getValue(); |
get_field('field_xxxxx', 'user_2458'); |
Gets the full field name of a field. Fields nested in fields like repeater, group or flexible content fields will also be returned as full field names.
With ACF you can only get the direct name of a field. This method allows you to get the full field name.
Let’s say you have a group of test_group_field
and a sub field of test_sub_field
in the group. Using the getName()
method you can get the full field name of the sub field: test_group_field_test_sub_field
.
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Devidw\ACF\Field\Field;
$fieldName = Field::setKey('field_xxxxx')::getName();
dump($fieldName);
Credits to Adam for the StackOverflow answer.
Documentation is available at https://devidw.github.io/acf-helper/api/