[英]ACF Repeater field not returning any fields from the data supplied in the frontend
I just installed ACF Plugin.我刚刚安装了 ACF 插件。 I have successfully created the fields I require.
我已经成功创建了我需要的字段。 I have a repeater field called
upload_documents
.我有一个名为
upload_documents
的转发器字段。
Under the repeater field, I have three fields.在转发器字段下,我有三个字段。 I have a select field called
document_type
, a file upload field called file
and a textfield called notes
.我有一个名为
document_type
的 select 字段、一个名为file
的文件上传字段和一个名为notes
的文本字段。 For the rules, I have set it to display for a page called Upload Documents
.对于规则,我已将其设置为显示在名为
Upload Documents
的页面上。
I am new to PHP.我是 PHP 的新手。 I know HTML and CSS.
我知道 HTML 和 CSS。 But either way, I have given it a go but I am stuck at this point.
但无论哪种方式,我都给了它一个 go 但我被困在这一点上。 It seems something is off which I can't seem to find out.
似乎有些东西我似乎无法找到。 I tried var_dump but they return null.
我尝试了 var_dump,但它们返回 null。 I have supplied the required details and uploaded to the fields.
我已提供所需的详细信息并上传到字段。 Here is what I have tried.
这是我尝试过的。 Please assist me.
请帮助我。
$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');
If you are new to PHP I can recommend this plugin https://hookturn.io/downloads/acf-theme-code-pro/ it will help you understand how ACF works.如果您是 PHP 的新手,我可以推荐这个插件https://hookturn.io/downloads/acf-theme-code-pro/它将帮助您了解 ACF 的工作原理。
Provided code it is output from act theme code pro for your repeater field upload_documents.提供的代码是 output 来自您的转发器字段 upload_documents 的 act 主题代码 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; ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.