Home › Forums › Backend Issues (wp-admin) › Can’t get dynamic repeater to display
Hi there,
I’m trying to build a more flexible template that allows the user to simply add content blocks that can be moved around using “Add Row” and then selecting from a dropdown of template blocks. I was using the advanced layout template as a guide and duplicated a number of content/template files. Exported the PHP and added to bottom of the function.php file, as well.
The problem is that when I try to use the new template, the “Add row” button doesn’t show up, so I can’t even tell if it’s partially working. I tried adding the new segments to the Advanced Layout Template but they don’t show up in the drop down either.
All of the new template files I’ve added were pulled from already existing template files, so I know they can work, but need something that’s not so rigid, as we currently can’t change anything or change the order without effecting every site on our website, and if we do add something, it simply doesn’t show up.
A number of the new field groups have custom names, not sure if that matters, tried just applying a new, different template to the page we want to change, but if I do that the page becomes blank on the front end, even though the back end shows content.
Here’s our template PHP page.
<?php
/**
* Template Name: Master Page Builder
*/
?>
<?php while (have_posts()) : the_post(); ?>
<?php //get_template_part('templates/page', 'header'); ?>
<?php get_template_part('templates/content', 'master-page-builder'); ?>
<?php endwhile; ?>
The content file associated with the template file is below.
<?php
// SETTINGS *** Lines 3-11, possibly unnecessary **
global $post;
$pid = $post->ID;
$pSlug = $post->slug;
$parentID = $post->post_parent;
// print $pid;
// print '<br>';
// print $parentID;
//$title = get_field('title');
$colour = get_field('theme_colour');
$hide_content = get_field('hide_content');
?>
<div class="trufflesTheme_<?php if ($colour) : print $colour; else : print 'indigo'; endif; ?> trufflesChildPage">
<?php
if ($hide_content) :
// Return Nothing
else : ?>
<section id="trufflesMainContent" class="sectionRow truffles_content">
<div class="inner">
<div class="margin">
<?php the_content(); ?>
</div>
</div>
</section>
<?php endif; ?>
<?php if (have_rows('master_content_type')) : ?>
<section id="truffles_contentWrapper" class="truffles_contentType truffles_content">
<?php while (have_rows('master_content_type')) : the_row();
// Available Variables under sub field 'select'
//full : Full Banner
//small : Smaller Banner
//imageanddesc : Image & Description
//altimageanddesc : Image & Description (Alternative)
//wysiwyg : Content Editor (WYSIWYG)
//accordions : Accordions
//logocloud : Logo Cloud
//photocolumns : Photo Columns
//topbanner : Header Banner
//introduction : Introduction & Booking
//cta : Call To Action
//testimonials: Testimonials
//testimonials: Video Banner
//linkblocks: Link Blocks
//homepageimgdesc: Image & Description Home Page Styling
//bannerheader: Text Header
$select = get_sub_field('select'); ?>
<section class="contentType_<?php print $select; ?> sectionRow">
<?php if ($select == 'full') : ?>
<?php get_template_part('templates/advanced', 'full'); ?>
<?php elseif ($select == 'small') : ?>
<?php get_template_part('templates/advanced', 'small'); ?>
<?php elseif ($select == 'imageanddesc') : ?>
<?php get_template_part('templates/advanced', 'imageanddesc'); ?>
<?php elseif ($select == 'altimageanddesc') : ?>
<?php get_template_part('templates/advanced', 'altimageanddesc'); ?>
<?php elseif ($select == 'wysiwyg') : ?>
<?php get_template_part('templates/advanced', 'wysiwyg'); ?>
<?php elseif ($select == 'accordions') : ?>
<?php get_template_part('templates/advanced', 'accordions'); ?>
<?php elseif ($select == 'logocloud') : ?>
<?php get_template_part('templates/advanced', 'logocloud'); ?>
<?php elseif ($select == 'photocolumns') : ?>
<?php get_template_part('templates/advanced', 'photocolumns'); ?>
<?php elseif ($select == 'three') : ?>
<?php get_template_part('templates/advanced', 'threecolumns'); ?>
<?php elseif ($select == 'embed') : ?>
<?php get_template_part('templates/advanced', 'embed'); ?>
<!-- New Content Fields -->
<?php elseif ($select == 'topbanner') : ?>
<?php get_template_part('templates/advanced', 'topbanner'); ?>
<?php elseif ($select == 'introduction') : ?>
<?php get_template_part('templates/advanced', 'introduction'); ?>
<?php elseif ($select == 'cta') : ?>
<?php get_template_part('templates/advanced', 'cta'); ?>
<?php elseif ($select == 'testimonials') : ?>
<?php get_template_part('templates/advanced', 'testimonials'); ?>
<?php elseif ($select == 'videobanner') : ?>
<?php get_template_part('templates/advanced', 'videobanner'); ?>
<?php elseif ($select == 'linkblocks') : ?>
<?php get_template_part('templates/advanced', 'linkblocks'); ?>
<?php elseif ($select == 'homepageimgdesc') : ?>
<?php get_template_part('templates/advanced', 'homepageimgdesc'); ?>
<?php elseif ($select == 'bannerheader') : ?>
<?php get_template_part('templates/advanced', 'bannerheader'); ?>
<!-- END New Content Fields -->
<?php endif; ?>
</section>
<?php endwhile; ?>
</section> <!-- END #truffles_contentWrapper -->
<?php endif; ?>
<?php get_template_part('templates/footer-landing'); ?>
</div><!-- end .trufflesTheme -->
And this is referencing a number of built out fields built in php, modelled after the structure of the advanced layout template.
Example below:
<?php
// TESTIMONIALS
$testimonials_section = get_sub_field('testimonials_section');
?>
<div class="innerTable">
<?php if($testimonials_section['section_content'] || $testimonials_section['testimonials_slider']):?>
<div class="testimonials-section">
<div class="container-wrap">
<?php if($testimonials_section['section_content']):?>
<div class="section-content">
<?php echo $testimonials_section['section_content'];?>
</div>
<?php endif;?>
<?php if($testimonials_section['testimonials_slider']):
echo testimonial_slider($testimonials_section['testimonials_slider']);
endif;?>
</div>
</div>
<?php endif;?>
</div>
Which is very similar to the advanced layout template fields, like this one below.
<?php
// VARIABLES
$image = get_sub_field(‘image’);
$desc = get_sub_field(‘description’);
?>
<div class=”innerTable”>
<?php if ($image) : ?>
<div class=”tableLeft”>
<div class=”imageBlock”>
<div class=”image”>
” alt=”Truffles Catering – <?php $image[‘alt’]; ?>” />
</div>
</div>
</div>
<?php endif; ?>
<?php if ($desc) : ?>
<div class=”tableRight”>
<div class=”descBlock”>
<div class=”desc”>
<?php print $desc; ?>
</div>
</div>
</div>
<?php endif; ?>
</div>
And lastly, here’s the PHP that I exported and added to the functions.php file.
/**
*
* Adding New Template and Registering it
*
* */
add_action( 'acf/include_fields', function() {
if ( ! function_exists( 'acf_add_local_field_group' ) ) {
return;
}
acf_add_local_field_group( array(
'key' => 'group_649377b3715ff',
'title' => 'Master Page Builder',
'fields' => array(
array(
'key' => 'field_649377b3bddda',
'label' => 'Master Content Type',
'name' => 'master_content_type',
'aria-label' => '',
'type' => 'repeater',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'collapsed' => '',
'min' => 0,
'max' => 0,
'layout' => 'block',
'button_label' => 'Add Content Row',
'sub_fields' => array(
),
),
array(
'key' => 'field_6493785744c19',
'label' => 'Navigation Menu',
'name' => 'navigation_menu',
'aria-label' => '',
'type' => 'select',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'choices' => array(
'main-navigation' => 'Main Navigation',
'secondary-menu' => 'Secondary Menu',
'footer-menu' => 'Footer Menu',
'weddings-menu' => 'Weddings Menu',
'corporate-functions-menu' => 'Corporate Functions Menu',
'social-events-menu' => 'Social Events Menu',
'truffles-express-menu' => 'Truffles Express Menu',
),
'default_value' => false,
'return_format' => 'value',
'multiple' => 0,
'allow_null' => 0,
'ui' => 0,
'ajax' => 0,
'placeholder' => '',
),
),
'location' => array(
array(
array(
'param' => 'page_template',
'operator' => '==',
'value' => 'template-master-page-builder.php',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
'show_in_rest' => 0,
) );
} );
Surely, it can’t be this difficult to use ACF? Can anyone help me get this to be visible so I can add content blocks on our back-end that anyone can add, move, and (most importantly) be seen on the front-end.
Thank you
There are no sub fields in your repeater named “master_content_type”
Should I change it to ‘content_type’ then, like the advanced custom layout?
I have the repeater ID labelled ‘master_content_type’
and then referenced in the content file:
<?php if (have_rows('master_content_type')) : ?>
<section id="truffles_contentWrapper" class="truffles_contentType truffles_content">
<?php while (have_rows('master_content_type')) : the_row();
// Available Variables under sub field 'select'
There’s also this code in the functions.php
add_action( 'acf/include_fields', function() {
if ( ! function_exists( 'acf_add_local_field_group' ) ) {
return;
}
acf_add_local_field_group( array(
'key' => 'group_649377b3715ff',
'title' => 'Master Page Builder',
'fields' => array(
array(
'key' => 'field_649377b3bddda',
'label' => 'Master Content Type',
'name' => 'master_content_type',
'aria-label' => '',
'type' => 'repeater',
Should I use JSON to register new fields?
I’ve labelled the repeater ID as ‘master_content_type’
And referenced it in the content php file.
<?php if (have_rows('master_content_type')) : ?>
<section id="truffles_contentWrapper" class="truffles_contentType truffles_content">
<?php while (have_rows('master_content_type')) : the_row();
// Available Variables under sub field 'select'
I also tried to register a new field in the functions.php file.
acf_add_local_field_group( array(
'key' => 'group_649377b3715ff',
'title' => 'Master Page Builder',
'fields' => array(
array(
'key' => 'field_649377b3bddda',
'label' => 'Master Content Type',
'name' => 'master_content_type',
'aria-label' => '',
'type' => 'repeater',
Should I be modifying something else? Or registering the new field with JSON?
I have no idea what you mean by “advanced custom layout”
key' => 'group_649377b3715ff',
'title' => 'Master Page Builder',
'fields' => array(
array(
'key' => 'field_649377b3bddda',
'label' => 'Master Content Type',
'name' => 'master_content_type',
'aria-label' => '',
'type' => 'repeater',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'collapsed' => '',
'min' => 0,
'max' => 0,
'layout' => 'block',
'button_label' => 'Add Content Row',
/* NO SUB FIELDS */
'sub_fields' => array(
),
),
You must be logged in to reply to this topic.
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.