I tried to follow the instructions here: https://support.advancedcustomfields.com/forums/topic/file-field-get-server-path-to-file-instead-of-url/
This is my field:
https://i.imgur.com/l3ifdmM.png
This is my code:
$order_id = $order->get_id();
$file = get_field('outlook_for_the_year', $order_id);
$file_url = $file['url'];
However, I get the error message “PHP Warning: Illegal string offset ‘url'”. Also, I do not get the file server path at all.
Can you let me know how to fix this?
Thanks
What it the field’s return value set to? It needs to be “File Array” to use $file['url']
You mean like this?
$order_id = $order->get_id();
$file = get_field(‘outlook_for_the_year’, $order_id);
$file_url =array();
$file_url = $file[‘url’];
Each field has a return format setting. If the file field is set to return an array then the value will already be set.
What is the field’s return value set to?
This reply has been marked as private.
You will not be able to get the file path of a file field with a return format of URL.
You need to get or return the ID of the file to use the code that you referenced. You can either change the return format of the field to ID or you can get the ID by getting the unformatted value
// https://www.advancedcustomfields.com/resources/get_field/
$id = get_field('file_field_name', false, false);