简体   繁体   中英

ACF repeater field showing outside of <li></li>

I have created a custom widget where I'm calling some ACF items in it. I have echoed out all my custom fields and they are working fine but for some reason my repeater field items are showing up outside of the <li> when I look at the source code? Any idea where I went wrong in my code?

    if( get_field('background') ):
    echo "<p class='contact-title'>Background/Experience</p>";
        echo "<ul>";
            while( have_rows('background') ): the_row();
            echo "<li>". the_sub_field('licences__permits__etc'). "</li>";
            endwhile;
        echo "</ul>";
    endif;

it outputs this

<p class="contact-title">Background/Experience</p>    
<ul>
    Babysitter
    <li></li>
    Driver's Permit
    <li></li>
    OG loc
    <li></li>
</ul>

the_field() functions echo-es the content. If you want to concatenate <li> with returned value, you must use get_sub_field() - it only returns value. So

echo "<li>". get_sub_field('licences__permits__etc'). "</li>";

or

echo "<li>";
the_sub_field('licences__permits__etc');
echo "</li>"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM