ACF Repeater 字段不返回前端提供的数据中的任何字段
ACF Repeater field not returning any fields from the data supplied in the frontend
我刚刚安装了 ACF 插件。我已经成功创建了我需要的字段。我有一个名为 upload_documents
的转发器字段。
在转发器字段下,我有三个字段。我有一个名为 document_type
的 select 字段、一个名为 file
的文件上传字段和一个名为 notes
的文本字段。对于规则,我将其设置为显示名为 Upload Documents
.
的页面
我是 PHP 的新手。我知道 HTML 和 CSS。但无论哪种方式,我都试过了,但我被困在了这一点上。似乎有些事情我似乎无法找到。我试过 var_dump 但它们 return 无效。我已经提供了所需的详细信息并上传到字段中。这是我试过的。请帮助我。
$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 的新手,我可以推荐这个插件 https://hookturn.io/downloads/acf-theme-code-pro/ 它会帮助您了解 ACF 的工作原理。
提供的代码是从 act theme code pro 为您的转发器字段输出的代码 upload_documents。
<?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; ?>
我刚刚安装了 ACF 插件。我已经成功创建了我需要的字段。我有一个名为 upload_documents
的转发器字段。
在转发器字段下,我有三个字段。我有一个名为 document_type
的 select 字段、一个名为 file
的文件上传字段和一个名为 notes
的文本字段。对于规则,我将其设置为显示名为 Upload Documents
.
我是 PHP 的新手。我知道 HTML 和 CSS。但无论哪种方式,我都试过了,但我被困在了这一点上。似乎有些事情我似乎无法找到。我试过 var_dump 但它们 return 无效。我已经提供了所需的详细信息并上传到字段中。这是我试过的。请帮助我。
$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 的新手,我可以推荐这个插件 https://hookturn.io/downloads/acf-theme-code-pro/ 它会帮助您了解 ACF 的工作原理。
提供的代码是从 act theme code pro 为您的转发器字段输出的代码 upload_documents。
<?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; ?>