Hello,
how can I display the text I entered in the append in the backend (in my case km and h) display also on the frontend behind the entered value?
$field = get_field_object('field_name');
echo $field['append'];
Hi there,
I am using Elementor to display the custom fields and I would like to display append and prepend for some values in the frontend.
I could not get it to work yet. Could you provide further instructions where to add the PHP code? I tried to paste it at the end of my themes functions.PHP file, but that did not show results. Do I paste it somewhere else?
1. I added to the PHP file:
$field = get_field_object('height');
echo $field['append'];
2. I added the code directly to my Elementor theme templates HTML:
<p><?php $field = get_field_object('height'); echo $field['append'];?></p>
I am not sure what I am getting wrong here. Are you able to help me?
many thanks!
Moritz
@moritzacf for this you need to create an acf/format_value filter. in the filter the field object is available and you can add the append or prepend value to the field value and then return it.
Hello,
I’m a fresh beginner with acf, and I’m trying to to display in front end the append & prepend for specific custom fields. how can be created the ‘acf/format_value filter’ in this case, in order to be visual? Thank you!
https://www.advancedcustomfields.com/resources/acf-format_value/
add_filter('acf/format_value/name=FIELD_NAME', 'MY_FUNCTION_NAME', 20, 3);
function MY_FUNCTION_NAME($value, $post_id, $field) {
$value = trim($field['prepend'].' '.$value.' '.$field['append']);
return $value;
}