Hi there!
Is there an easy way to display more than just one field in the same php line? I’m asking this because I need to display many fields (that are in different groups) in the same place.
I’ve tried to use the following, but didn’t worked:
<?php get_fields('field-name-1','field-name-2','field-name-3'); ?>
ACF has this feature?
Thanks a lot in advance!
There isn’t any way to do what you’re looking for. There is get_field() that gets one value from one field https://www.advancedcustomfields.com/resources/get_field/ and there is get_field() that gets all the values for all the fields on a page https://www.advancedcustomfields.com/resources/get_fields/
If you want to get a list of specific fields then you’d need to call get_field() for each.
$field_names = array('field-name-1','field-name-2','field-name-3');
$fields = array();
foreach ($field_names as $field_name) {
$fields[$field_name] = get_field($field_name);
}
Fantastic!!!
Actually, I just wanted something to keep all my field organized into my php file. So, this is exactly what I was looking for.
I just needed to change the line:
$fields[$field_name] = get_field($field_name);
to
$fields[$field_name] = the_field($field_name);
Thank you dude!