Home › Forums › Add-ons › Repeater Field › Advanced loop error › Reply To: Advanced loop error
Thanks for replying James. Sorry it took so long for me to view this. Here is what is happening:
I have a repeater setup on our corp. site. It’s a list of all of our resources. In the ACF in WordPress, I have a Repeater (resources) that has 11 sub-fields. A few of the resources are videos, so I have javascript functions that allow for lightbox video views. For the resources that are videos, I have conditional logic setup in the ACF in WordPress that says if Type is equal to video, show these 4 fields. When I fill out the forms on the WordPress page, everything looks good at this point. If I select type equal to video, the appropriate 4 fields show and I can enter the values.
The problem is once this WordPress page is saved and I view the page, some of the other resources that are not videos have the javascript code associated with them. I thought I had it setup correct but obviously not. My php logic was to show the javascript code only if a value existed. Since all the resources that aren’t videos don’t have a particular field value, I thought that would work. Below is the actual code from the page:
<?php if( have_rows('resources') ): ?>
<ul id="Resource-Grid" class="list-unstyled">
<?php while( have_rows('resources') ): the_row();
// vars
$date = get_sub_field('date');
$featured = get_sub_field('featured');
$type = get_sub_field('type');
$topic = get_sub_field('topic');
$data_date = get_sub_field('data_date');
$link = get_sub_field('link');
$image = get_sub_field('image');
$title = get_sub_field('title');
$icon = get_sub_field('icon');
$download_label = get_sub_field('download_label');
$label_type = get_sub_field('label_type');
$embed_code = get_sub_field('embed_code');
$link_id = get_sub_field('link_id');
$function_id = get_sub_field('function_id');
$variable_id = get_sub_field('variable_id');
?>
<li data-date="<?php echo $data_date; ?>" class="mix <?php echo $topic; ?> <?php echo $type; ?> <?php echo $featured; ?> col-sm-6 col-lg-4">
<?php if( $embed_code ): ?>
<script type="text/javascript" id="vidyard_embed_code_<?php echo $embed_code; ?>" src="//play.vidyard.com/<?php echo $embed_code; ?>.js?v=3.1&type=lightbox"></script>
<script type="text/javascript">
window.onload = function() {
var <?php echo $variable_id; ?> = document.getElementById("<?php echo $link_id; ?>");
<?php echo $variable_id; ?>.onclick = function() {
fn_vidyard_<?php echo $function_id; ?>();
return false;
}
}
</script>
<?php endif; ?>
<a <?php if( $embed_code ): ?> id="<?php echo $link_id; ?>" onclick="fn_vidyard_<?php echo $function_id; ?>();" <?php endif; ?> href="<?php echo $link; ?>" target="_blank">
<div class="resource-item">
<div class="resource-img-container">
<div class="resource-overlay"><span class="btn btn-small white-outline"><i class="fa fa-<?php echo $icon; ?>"></i> <?php echo $download_label; ?> <?php echo $label_type; ?><span></div>
<img src="<?php echo $image; ?>" alt="" class="img-responsive"></div>
<div class="resource-content">
<div class="resource-date"><?php echo $date; ?></div>
<div class="resource-type"><?php echo $type; ?></div>
<p class="resource-title"><?php echo $title; ?></p>
</div>
</div>
</a> </li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
Using Developer Tools, here is what is showing in the rendered HTML for a resource whose type is NOT equal to video:
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!
🚀 This week’s session of ACF Chat Fridays dips into the preliminary results of our first ever user survey. Don’t miss it! https://t.co/3UtvQbDwNm pic.twitter.com/kMwhaJTkZc
— Advanced Custom Fields (@wp_acf) May 9, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.