I just installed ACF Plugin. I have successfully created the fields I require. I have a repeater field called 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
. For the rules, I have set it to display for a page called Upload Documents
.
I am new to PHP. I know HTML and CSS. But either way, I have given it a go but I am stuck at this point. It seems something is off which I can't seem to find out. I tried var_dump but they return 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.
Provided code it is output from act theme code pro for your repeater field 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; ?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.