Home › Forums › General Issues › Using unique ID/Slug in template › Reply To: Using unique ID/Slug in template
I’m having a similar issue with a previous developer’s code, but can’t figure it out. I’m working on a page that has 2 arrays inside a loop using repeaters for an accordion drop down of sub fields and dumping all this into a boostrap card grid.
Basic structure:
– if custom query have posts : while custom query have posts : custom query the post
– if in array
– if in array
– count
– while have rows
– get sub fields
– count++
– endwhile
– else
– count
– while have rows
– get sub fields
– count++
– endwhile
– endwhile ; endif
– reset query
I think it definitely has a unique id issue since both arrays and the “else” section share the same repeater rows, fields and sub fields. What am I doing wrong? The else section near the bottom is the only part that works.
The 2 arrays handle this page (not working): http://dev-une-online-testing.pantheonsite.io/about/about-owl/academic-programs/
The else section shows in this page (working): http://dev-une-online-testing.pantheonsite.io/about/about-owl/
Help?
<?php
function owl_shortcode($atts) {
ob_start();
extract(shortcode_atts (array(
'category' => '',
'name' => '',
'orderby' => 'title'
), $atts));
if ($category) {
$cats = explode(",", $category);
$array = array();
for ($i = 0; $i < count($cats); ++$i) {
$array[] = get_category_by_slug($cats[$i])->term_id;
}
$custom_query = new WP_Query( array(
'category__and' => $array,
'post_type' => 'owl',
'orderby' => $orderby,
'order' => 'ASC',
'posts_per_page' => -1
));
}
else {
$custom_query = new WP_Query( array(
'post_type' => 'owl',
'orderby' => $orderby,
'order' => 'ASC',
'posts_per_page' => -1
));
}
?>
<div class="row">
<ul class="none">
<?php if ( $custom_query->have_posts() ): while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
<div class="col-sm-6">
<li class="card containFloat">
<?php //image ?>
<div class="circle">
<?php $image = get_field('image');
if( !empty($image) ):
$size = 'thumbnail';
$thumb = $image['sizes'][ $size ]; ?>
<img src="<?php echo $thumb; ?>" alt="<?php echo $image['alt']; ?>" />
<?php else: ?>
<img src="https://online.une.edu/wp-content/uploads/2018/06/blank-female-profile.jpg" alt="" height="150px" width="150px"/>
<?php endif; ?>
</div>
<?php if (in_array("program-administrator", $cats) || in_array("program-manager", $cats) || in_array("program-staff", $cats)) { ?>
<div class="containFloat">
<h2 class="margin-top">
<?php the_title(); ?>
<?php if (get_field('degree')) echo ', ' . get_field('degree'); ?>
</h2>
<p><?php the_field('job_title'); ?></p>
<p><i class="fas fa-phone"></i> <?php the_field('phone'); ?> </p>
<p><a href="mailto:<?php the_field('email'); ?>"><i class="fas fa-envelope-open"></i> <?php the_field('email'); ?></a></p>
<br>
</div>
<?php if (in_array("program-administrator", $cats) || in_array("program-manager", $cats)) { ?>
<div class="clearBoth">
<!--- Accordion Expander - OWL Shortcode Test - NOT WORKING --->
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<?php
//$uniqueid = get_sub_field( 'collapser' );
$uniqueid = uniqid('collapser');
$count = 0;
while ( have_rows( 'collapser' ) ) : the_row(); ?>
<div class="panel panel-default listbox">
<div class="panel-heading" role="tab" id="headingTwo">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse-<?php echo esc_attr( $uniqueid ); ?>-<?php echo esc_attr( $count ); ?>" aria-expanded="false">
<?php the_sub_field( 'expand_row') ?>
</a>
</div>
<div id="collapse-<?php echo esc_attr( $uniqueid ); ?>-<?php echo esc_attr( $count ); ?>" class="panel-collapse collapse" role="tabpanel">
<div class="panel-body">
<?php if (get_sub_field('description')) { ?>
<div class="panel-text"><b>More info</b><?php the_sub_field('description'); ?></div>
<?php } ?>
<?php if (get_sub_field('education')) { ?>
<div class="panel-text"><b>Education</b><?php the_sub_field('education'); ?></div>
<?php } ?>
<?php if (get_sub_field('expertise')) { ?>
<div class="panel-text"><b>Expertise</b><?php the_sub_field('expertise'); ?></div>
<?php } ?>
<?php if (get_sub_field('experience')) { ?>
<div class="panel-text"><b>Experience</b><?php the_sub_field('experience'); ?></div>
<?php } ?>
<?php if (get_sub_field('research')) { ?>
<div class="panel-text"><b>Research Interests</b><?php the_sub_field('research'); ?></div>
<?php } ?>
<?php if (get_sub_field('publications')) { ?>
<div class="panel-text"><b>Publications</b><?php the_sub_field('publications'); ?></div>
<?php } ?>
<?php if (get_sub_field('bio')) { ?>
<div class="panel-text"><b>Bio</b><?php the_sub_field('bio'); ?></div>
<?php } ?>
</div>
</div>
</div>
<?php $count ++; ?>
<?php endwhile; ?>
</div>
</div>
<?php } ?>
<?php } else { ?>
<div class="containFloat">
<h2><?php the_title(); ?></h2>
<p><?php the_field('job_title'); ?></p>
<p><i class="fas fa-phone"></i> <?php the_field('phone'); ?> </p>
<p><i class="fas fa-envelope-open"></i> <a href="mailto:<?php the_field('email'); ?>"> <?php the_field('email'); ?></a></p><br>
</div>
<!--- Accordion Expander - OWL.php WORKING --->
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<?php
//$uniqueid = get_sub_field( 'collapser' );
$uniqueid = uniqid('collapser');
$count = 0;
while ( have_rows( 'collapser' ) ) : the_row(); ?>
<div class="panel panel-default listbox">
<div class="panel-heading" role="tab" id="headingTwo">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse-<?php echo esc_attr( $uniqueid ); ?>-<?php echo esc_attr( $count ); ?>" aria-expanded="false">
<?php the_sub_field( 'expand_row' ) ?>
</a>
</div>
<div id="collapse-<?php echo esc_attr( $uniqueid ); ?>-<?php echo esc_attr( $count ); ?>" class="panel-collapse collapse" role="tabpanel">
<div class="panel-body">
<?php if (get_sub_field('description')) { ?>
<div class="panel-text"><b>More info</b><?php the_sub_field('description'); ?></div>
<?php } ?>
<?php if (get_sub_field('expertise')) { ?>
<div class="panel-text"><b>Expertise</b><?php the_sub_field('expertise'); ?></div>
<?php } ?>
</div>
</div>
</div>
<?php $count ++; ?>
<?php endwhile; ?>
</div>
<!--- End Accordion --->
<?php } ?>
</li>
</div>
<?php endwhile; endif; ?>
</ul>
</div>
<?php
wp_reset_query();
return ob_get_clean();
}
?>
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.