StoutLogic / acf-builder

An Advanced Custom Field Configuration Builder
GNU General Public License v2.0
794 stars 62 forks source link

Image field return_format returns an ID instead of array or URL #163

Open marcinkrzeminski opened 1 year ago

marcinkrzeminski commented 1 year ago

Hi,

I have an image field added like this

->addImage('image', [
            'label' => __('Image'),
            'return_format' => 'url'
        ])

As per docs, this should return a URL to the image. Unfortunately, I'm getting and ID in the response.

public 'acf' => 
    object(stdClass)[12748]
      public 'email' => string 'test@test.com' (length=21)
      public 'image' => int 875
      public 'bio' => string '' 

Any idea what could be wrong here?

timlogemann commented 1 year ago

I noticed the same for radio and other fields where the return_format option can be provided. It always seems to return the default setting rather than the value provided. For a radio I tried setting it to both label and array, but it still returns just the value.

For example this radio:


->addRadio('language', ['return_format' => 'array'])
  ->setConfig('label', __('Language', 'deerns'))
  ->setConfig('return_format', 'array')
  ->setConfig('required', true)
  ->addChoices([
    'nl' => __('Dutch', 'deerns'),
    'en' => __('English', 'deerns'),
    'fr' => __('French', 'deerns'),
    'de' => __('German', 'deerns'),
    'it' => __('Italian', 'deerns'),
    'pt' => __('Portuguese', 'deerns'),
    'es' => __('Spanish', 'deerns')
  ])```

as you can see I've tried setting the return_format in both the inline settings array as well as with the setConfig option, after trying them both separately, but they have no effect. The field only returns 'es' for example.
ernilambar commented 1 year ago

I tested Image and Radio fields and both are working fine. Can you please provide sample code how are you fetching the ACF field value?