Hi I have a definition list which i am trying to hide the <dt> and <dd> for specific repeater fields that do not have any content. I have tried a few different approaches in the forum but none seem to be working for me.
So I need it to hide the dd and corresponding dt. For example I want to hide the engine sub_field and also the engine <dt>. Any help would be wonderful!
<!-- model specifications -->
<?php if( have_rows('model_specifications') ): ?>
<div id="model-specifications">
<dl>
<dt class="model">Model</dt>
<dt class="gpm">GPM</dt>
<dt class="psi">PSI</dt>
<dt class="drive">Drive RPM</dt>
<dt class="hp-volt">HP / Volt</dt>
<dt class="engine">Engine</dt>
<dt class="request-quote">Quote</dt>
<?php while( have_rows('model_specifications') ): the_row(); ?>
<dd class="model"><?php the_sub_field('model'); ?></dd>
<dd class="gpm"><?php the_sub_field('gpm'); ?></dd>
<dd class="psi"><?php the_sub_field('psi'); ?></dd>
<dd class="drive"><?php the_sub_field('drive'); ?></dd>
<dd class="hp-volt"><?php the_sub_field('hp-volt'); ?></dd>
<dd class="engine"><?php the_sub_field('engine'); ?></dd>
<dd class="request-quote"><a href="/request-a-quote/">Request Quote</a></dd>
<?php endwhile; ?>
</dl>
<p><?php the_field('model_specification_notes'); ?></p>
</div>
<?php endif; ?>
<!-- end model specifications -->
it is possible, just check if value is there
but for that you need to re-arrange / re-write your code.
here a part of it. just add the other rows the same way.
<?php if( have_rows('model_specifications') ):
while( have_rows('model_specifications') ): the_row();
$ms_model = get_sub_field('model');
$ms_gpm = get_sub_field('gpm');
endwhile;
echo '<div id="model-specifications">';
echo '<dl>';
if ($ms_model) {echo '<dt class="model">Model</dt>';}
if ($ms_gpm) {echo '<dt class="gpm">GPM</dt>';}
if ($ms_model) {echo '<dd class="model">'.$ms_model.'</dd>';}
if ($ms_gpm) {echo '<dd class="gpm">'.$ms_gpm.'</dd>';}
echo '</dl>';
?>
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!
🚀 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.