i would like to show an acf field in the loop-markup.php
When i use something like the following code in the content div, the new div is not shown an the field appears outside the grid item (screenshot attached)
$markup .= '<div class="test">';
$markup .= the_field('alter');
$markup .= '</div>';
What should i do to put an acf field as php code inside the content div?
thanks for your help. Now i get the „Warning: Array to string conversion“. The ACF Field is a choice Field. How can i get the selected Value instead of the whole array?
Thank you Tahir! But i still would like to write a flexible code in the loop-markup.php, so it would be perfect to get the selected Values instead of the whole array from AFC in the loop-markup.php.
To get only the selected values from an ACF field in loop-markup.php, use get_field() and ensure the return format for that field in ACF settings is set to "Value" instead of "Label" or "Both". This ensures you receive just the raw selected values.
If the field allows multiple selections, the result will be an array. You can work with individual values from it or just pick the first one if needed. If the field is a single-select, you'll get a single value directly.
For more complex fields like repeaters or groups, the structure is different. You’d access individual subfields or loop through rows depending on the setup.
Thanks! I found the solution now. it looks like he didn't know which ID to use, so i used the funktion $post_id = get_the_ID(); and then added the post_id to the field: $markup .= get_field('alter', $post_id);
Hello,
i would like to show an acf field in the loop-markup.php
When i use something like the following code in the content div, the new div is not shown an the field appears outside the grid item (screenshot attached)
$markup .= '<div class="test">';
$markup .= the_field('alter');
$markup .= '</div>';
What should i do to put an acf field as php code inside the content div?
Thanks for your suppourt
Attached files: Bildschirmfoto 2025-07-13 um 12.49.50.png
Hi Iyad,
Thank you for writing to us.
This is happening because the the_field() function in ACF immediately prints the value to the page.
To fix this, you need to use get_field() instead, which returns the value so you can add it to your markup variable correctly.
Please replace your code with this:
Hope this does the trick!
Best wishes,
Salient Theme Support
Hello Noah,
thanks for your help. Now i get the „Warning: Array to string conversion“. The ACF Field is a choice Field. How can i get the selected Value instead of the whole array?
it works fine now for text fields
Best Regards
Hey Again,
Thanks for reaching out! .
The "Post Loop Builder" already has a Custom Field feature that you can use . See screenshot:
Best,
Salient Support Team
Thank you Tahir! But i still would like to write a flexible code in the loop-markup.php, so it would be perfect to get the selected Values instead of the whole array from AFC in the loop-markup.php.
Best Regards
Hi Again,
To get only the selected values from an ACF field in loop-markup.php, use get_field() and ensure the return format for that field in ACF settings is set to "Value" instead of "Label" or "Both". This ensures you receive just the raw selected values.
If the field allows multiple selections, the result will be an array. You can work with individual values from it or just pick the first one if needed. If the field is a single-select, you'll get a single value directly.
For more complex fields like repeaters or groups, the structure is different. You’d access individual subfields or loop through rows depending on the setup.
Thanks
Salient Support Team
Thanks! I found the solution now. it looks like he didn't know which ID to use, so i used the funktion
$post_id = get_the_ID();
and then added the post_id to the field:
$markup .= get_field('alter', $post_id);
Glad to help! .
Salient Support Team