【问题标题】:ACF Repeater field not returning any fields from the data supplied in the frontendACF 中继器字段未从前端提供的数据中返回任何字段
【发布时间】:2020-04-27 22:51:26
【问题描述】:

我刚刚安装了 ACF 插件。我已经成功创建了我需要的字段。我有一个名为upload_documents 的转发器字段。

在转发器字段下,我有三个字段。我有一个名为document_type 的选择字段、一个名为file 的文件上传字段和一个名为notes 的文本字段。对于规则,我已将其设置为在名为 Upload Documents 的页面上显示。

我是 PHP 新手。我知道 HTML 和 CSS。但无论哪种方式,我已经尝试过了,但我被困在了这一点上。似乎有些东西我似乎无法找到。我尝试了 var_dump,但它们返回 null。我已提供所需的详细信息并上传到字段。这是我尝试过的。请帮助我。


$user_id = get_current_user_id();
ob_start(); ?>
<?php if( have_rows('upload_documents',"user_{$user_id}" ) ): ?>

<table>
   <tr>
    <td>Column 1 header</td><td>Column 2 header</td><td>Column 3 header</td><td>Column 4 header</td>
   </tr>

<?php while ( have_rows('upload_documents', "user_{$user_id}" ) ) : the_row(); 

    // vars
    $var1 = get_sub_field('document_type');
    $var2 = get_sub_field('file');
    $var3 = get_sub_field('notes');
    $var4 = get_sub_field('subfield_4_name');

?>
    <tr>
        <td><?php echo $var1; ?></td><td><?php echo $var2; ?></td><td><?php echo $var3; ?></td><td><?php echo $var4; ?></td>
    </tr>


<?php endwhile; ?>

</table>
<?php else: echo '<span>No data</span>'; ?>
<?php endif; ?>
<?php $output = ob_get_clean();
return $output;
}

add_shortcode('acf_repeater_shortcode', 'acf_repeater');

【问题讨论】:

  • 问题的状态如何?给出答案。

标签: php advanced-custom-fields


【解决方案1】:

如果您是 PHP 新手,我可以推荐这个插件 https://hookturn.io/downloads/acf-theme-code-pro/,它将帮助您了解 ACF 的工作原理。

为您的转发器字段upload_documents提供从act theme code pro输出的代码。

<?php if ( have_rows( 'upload_documents' ) ) : ?>
    <?php while ( have_rows( 'upload_documents' ) ) : the_row(); ?>
        <?php the_sub_field( 'document_type' ); ?>
        <?php $file = get_sub_field( 'file' ); ?>
        <?php if ( $file ) { ?>
            <a href="<?php echo $file['url']; ?>"><?php echo $file['filename']; ?></a>
        <?php } ?>
        <?php the_sub_field( 'notes' ); ?>
    <?php endwhile; ?>
<?php else : ?>
    <?php // no rows found ?>
<?php endif; ?>

【讨论】:

    猜你喜欢
    • 2020-06-14
    • 2017-03-17
    • 2019-03-30
    • 2017-01-01
    • 2014-07-04
    • 2014-09-22
    • 2018-07-17
    • 2015-02-17
    • 2021-04-16
    相关资源
    最近更新 更多