Home › Forums › Add-ons › Repeater Field › Display Repeater Values on Post Page
Hi,
Apologies if this is a newbie question from a novice coder but having read the documentation the answer is unclear to me. I am using ACF Pro (current version) and have a repeater setup with 4 sub-fields, the code for the set-up is:
if( function_exists('register_field_group') ):
register_field_group(array (
'key' => 'group_55034c2e80cd6',
'title' => 'Address Details',
'fields' => array (
array (
'key' => 'field_55034c470a82f',
'label' => 'Address Details',
'name' => 'address_details',
'prefix' => '',
'type' => 'repeater',
'instructions' => '',
'required' => 1,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'min' => '',
'max' => 100,
'layout' => 'table',
'button_label' => 'Add Row',
'sub_fields' => array (
array (
'key' => 'field_55034cc00a830',
'label' => 'Date Added',
'name' => 'date_added',
'prefix' => '',
'type' => 'date_picker',
'instructions' => '',
'required' => 1,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'display_format' => 'd/m/Y',
'return_format' => 'F j, Y',
'first_day' => 1,
),
array (
'key' => 'field_55034d370a831',
'label' => 'Address',
'name' => 'address',
'prefix' => '',
'type' => 'textarea',
'instructions' => '',
'required' => 1,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'maxlength' => '',
'rows' => '',
'new_lines' => 'wpautop',
'readonly' => 0,
'disabled' => 0,
),
array (
'key' => 'field_55034d840a832',
'label' => 'Author',
'name' => 'author',
'prefix' => '',
'type' => 'text',
'instructions' => '',
'required' => 1,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => 'AutographSearch',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
'readonly' => 0,
'disabled' => 0,
),
array (
'key' => 'field_55034dc50a833',
'label' => 'Status',
'name' => 'status',
'prefix' => '',
'type' => 'select',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'choices' => array (
'active' => 'Active',
'expired' => 'Expired',
),
'default_value' => array (
'' => '',
),
'allow_null' => 0,
'multiple' => 0,
'ui' => 0,
'ajax' => 0,
'placeholder' => '',
'disabled' => 0,
'readonly' => 0,
),
),
),
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'post',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
));
endif;
I am also using a child theme and I am working on the assumption that as the fields will be displayed on a standard post the code needs to be inserted into single.php in the child theme. The code for the child theme without any modifications is:
<?php
/**
* The template for displaying a single post
*
* @package Layers
* @since Layers 1.0.0
*/
get_header(); ?>
<section id="post-<?php the_ID(); ?>" <?php post_class( 'content-main clearfix' ); ?>>
<div class="row">
<?php get_sidebar( 'left' ); ?>
<?php if( have_posts() ) : ?>
<?php while( have_posts() ) : the_post(); ?>
<article <?php layers_center_column_class(); ?>>
<?php get_template_part( 'partials/content', 'single' ); ?>
</article>
<?php endwhile; // while has_post(); ?>
<?php endif; // if has_post() ?>
<?php get_sidebar( 'right' ); ?>
</div>
</section>
<?php get_footer(); ?>
I have tried multiple ways to get the repeater fields to display without success, can anyone help?
Thanks in advance
Graham
I should also have mentioned in my post above that I want to display the outputs in a table below the post content.
did you get a output when you use something like this? :
<?php
// check if the repeater field has rows of data
if( have_rows('address_details') ):
// loop through the rows of data
while ( have_rows('address_details') ) : the_row();
// display a sub field value
the_sub_field('address');
the_sub_field('author');
endwhile;
else :
// no rows found
endif;
?>
The topic ‘Display Repeater Values on Post Page’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.