PHP code example of hanamura / acf-util
1. Go to this page and download the library: Download hanamura/acf-util library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hanamura / acf-util example snippets
// initialize AcfValue with field objects for specific post
// note: `get_field_objects()` is a buildin function of Advanced Custom Fields
$acf_value = new AcfUtil\AcfValue(get_field_objects($id));
// access field
$value = $acf_value->field_name;
// access repeater field
$value = $acf_value->repeater_field_name;
foreach (var $acf_value->repeater_field_name as $repeater_field) {
// child field is also AcfValue object
$value = $repeater_field->field_name;
// deeper repeater fields are accessible
foreach (var $repeater_field->deeper_repeater_field_name as $deeper_repeater_field) {
// this is also AcfValue object
$value = $deeper_repeater_field->field_name;
}
}