My code below is checking to see if a Wordpress member is male or female, and the displaying certain code based on this. I am trying to optimise the code below to avoid having to have 2 copies of the entire code block, as it appears to me that I only need to conditionally check the first piece of ACF if code, as this is referring to the gender specific content? How can I achieve this?
The current code below is working correctly, but results in lots of duplicate code. The attempt below does not work, it appears to be getting confused with the <? endif; ?>
tags?
CURRENT
<?php if ($memberGender == "male") : ?>
<section>
<?php if( have_rows('accordion_section_boys') ): ?>
<?php while( have_rows('accordion_section_boys') ): the_row(); ?>
<div class="accordion-section">
BOY SPECIFIC CONTENT
</div>
<?php endwhile; ?>
<?php endif; ?>
</section>
<?php endif; ?>
<?php if ($memberGender == "female") : ?>
<section>
<?php if( have_rows('accordion_section_boys') ): ?>
<?php while( have_rows('accordion_section_boys') ): the_row(); ?>
<div class="accordion-section">
GIRL SPECIFIC CONTENT
</div>
<?php endwhile; ?>
<?php endif; ?>
</section>
<?php endif; ?>
ATTEMPT
<section>
<?php if ($memberGender == "male") : ?>
<?php if( have_rows('accordion_section_boys') ): ?>
<?php while( have_rows('accordion_section_boys') ): the_row(); ?>
<?php endif; ?>
<?php if ($memberGender == "female") : ?>
<?php if( have_rows('accordion_section_girls') ): ?>
<?php while( have_rows('accordion_section_girls') ): the_row(); ?>
<?php endif; ?>
<div class="accordion-section">
GENDER SPECIFIC CONTENT (BOY OR GIRL)
</div>
<?php endwhile; ?>
<?php endif; ?>
</section>
<?php endif; ?>