【问题标题】:WordPress ACFL Display Relationship Field Within RepeaterWordPress ACFL 显示中继器中的关系字段
【发布时间】:2015-11-10 16:10:46
【问题描述】:

我有 WordPress 和 ACF。这是我用来显示转发器字段的代码

<?php

// check if the repeater field has rows of data
if( have_rows('lineup') ):

    // loop through the rows of data
    while ( have_rows('lineup') ) : the_row();

        // display a sub field value
        echo '<p>';
        the_sub_field('stage');
        echo ' on ';
        the_sub_field('date');
        the_sub_field('artists');
        echo '</p>';

    endwhile;

else :

    // no rows found

endif;

?>

如果我注释掉艺术家行(这是关系字段),输出是几个阶段和时间段。如果我把它留在里面,源代码的 HTML 会在第一个日期的末尾停止

我的问题是如何在转发器字段中显示关系字段

谢谢

【问题讨论】:

    标签: wordpress advanced-custom-fields


    【解决方案1】:
    <?php
    
    // check if the repeater field has rows of data
    if (have_rows('lineup')):
    // loop through the rows of data
        while (have_rows('lineup')):
            the_row();
    
            // display a sub field value
            echo '<p>';
            the_sub_field('stage');
            echo ' on ';
            the_sub_field('date');
            echo '</p>';
    
            $myposts = get_sub_field('artists');
    
            if ($myposts):
    ?>
                               <ul>
                                    <?php
                foreach ($myposts as $post_object):
    ?>
    
                                        <li><a href="<?php
                    echo get_permalink($post_object->ID);
    ?>"><?php
                    echo get_the_title($post_object->ID);
    ?></a></li>
    
                                    <?php
                endforeach;
    ?>
                               </ul>
                                <?php
            endif;
        endwhile;
    else:
    // no rows found
    endif;
    
    ?>
    

    【讨论】:

      猜你喜欢
      • 2017-01-01
      • 2014-04-02
      • 2018-04-11
      • 2019-03-30
      • 1970-01-01
      • 2019-10-16
      • 1970-01-01
      • 2018-02-10
      • 1970-01-01
      相关资源
      最近更新 更多