This package converts the return values of ACF to objects with easy-to-use methods.
Instead of calling get_field('selector'), you can use the AcfObjects facade: AcfObjects::getField('selector')
composer require tombroucke/acf-objects
You might have to clear wp acorn cache: wp acorn optimize:clear
When getting the value for a Checkbox field, an Illuminate/Support/Collection will be returned.
$checkboxValues = AcfObjects::getField('checkbox');{{ AcfObjects::getField('color_picker') }}When getting the value for a DatePicker field, a Carbon instance will be returned. If the field has no value, a FallbackField will be returned.
AcfObjects::getField('date')@if(AcfObjects::getField('date')->isSet())
AcfObjects::getField('date')->format(get_option('date_format))
@endifWhen getting the value for a DateTimePicker field, a Carbon instance will be returned. If the field has no value, a FallbackField will be returned.
AcfObjects::getField('date_time'){{ AcfObjects::getField('email')->obfuscate() }}{{ AcfObjects::getField('file')->url() }}
{{ AcfObjects::getField('file')->title() }}
{{ AcfObjects::getField('file')->filesize() }}When getting the value for a Group field, an Illuminate/Support/Collection will be returned.
@foreach (AcfObjects::getField('gallery') as $image)
<a href="{{ $image->url('large') }}">
{!! $image->image('medium') !!}
</a>
@endforeach{{ AcfObjects::getField('google_map')->address() }}
{{ AcfObjects::getField('google_map')->lat() }}
{{ AcfObjects::getField('google_map')->long() }} $settings = AcfObjects::getField('settings')
->default([
'foo' => 'bar'
]);
echo $settings->get('foo');{{ AcfObjects::getField('settings')->get('name') }}{!!
AcfObjects::getField('image')
->url('medium');
!!}
{!!
AcfObjects::getField('image')
->attributes(['class' => 'w-100 h-100 object-fit-cover'])
->image('thumbnail');
!!}
{!!
AcfObjects::getField('image')
->default(asset('image/placeholder.jpg')->uri())
->image('thumbnail');
!!}{{ AcfObjects::getField('link')->url() }}
@php
$link = AcfObjects::getField('link');
@endphp
@if($link->isSet())
<a href="{{ $link->url() }}" target="{{ $link->target() }}">
{{ $link->title() }}
</a>
@endif
// or
@if($link->isSet())
{!! $link->link() !!}
@endif{{ AcfObjects::getField('number') }}When getting the value for a Repeater field, an Illuminate/Support/Collection will be returned.
AcfObjects::getField('repeater')@unless(AcfObjects::getField('repeater')->isEmpty())
<ul>
@foreach(AcfObjects::getField('repeater') as $item)
<li>{!! $item['name'] !!}</li>
@endforeach
</ul>
@endunless{{ AcfObjects::getField('text')->default(get_the_title()) }}{{ AcfObjects::getField('text_area') }}- Acf::getField(
+ AcfObjects::getField(- Acf::get_field(
+ AcfObjects::getField(- use Otomaties\AcfObjects\Acf;
+ use Otomaties\AcfObjects\Facades\AcfObjects;- $repeater->get('sub_field')
+ $repeater['sub_field']