I’m creating a test system that is driven by WordPress where each answer is input with a true/false text box to say whether it’s the correct answer of not.
I’ve created a loop that outputs the answers with a checkbox next to it:
<?php if(get_sub_field('answer_options')): ?>
<?php while(has_sub_field('answer_options')): ?>
<p class="contact-form">
<input style="width: 20px;" type="checkbox" name="CheckboxGroup<?php echo $counter; ?>[]" value="<?php echo the_sub_field('answer'); ?>" />
<?php echo the_sub_field('answer'); ?>
</p>
<?php endwhile; ?>
<?php endif; ?>
How can I add code to that to include whether the answer is the correct one? I can do a conditional statement like the following to check which answer is correct but how can I incorporate that with the code above?
It needs to check which is the correct answer and also whether the user has ticked the correct/incorrect checkbox.
if( get_sub_field('correct') )
{
echo "do something";
}
else
{
echo "do something else";
}
Solved with the following: