douyan2970 2016-01-27 15:11
浏览 51
已采纳

ACF中继器字段显示在<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>
  • 写回答

1条回答 默认 最新

  • doudao1922 2016-01-27 18:35
    关注

    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>"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?