Okay
  Public Ticket #4146287
acf fields integration
Open

Comments

  • Iyad started the conversation

    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:  Bildschirm­foto 2025-07-13 um 12.49.50.png

  •  328
    Noah replied

    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:

    $markup .= '<div class="test">';
    $markup .= get_field('alter');
    $markup .= '</div>';
    

    Hope this does the trick!

     

    Best wishes,

    Salient Support

  • Iyad replied

    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

  •  9,343
    Tahir replied

    Hey Again,

    Thanks for reaching out! .

    The Post Loop Builder already has a Custom Field feature that you can use . See screenshot:  9806008243.png

    Best,

     


     Salient Support Team