Support

Account

Home Forums Front-end Issues Auto populate a dropdown menu from checkbox field

Solved

Auto populate a dropdown menu from checkbox field

  • I have a checkbox field with all the provinces of my country. Depending on the product, the client can choose which province that product is sold in from the backend.

    On the frontend of my site, I need to be able to create a dropdown menu that is auto populated with the province options that were selected from the backend.

    So far, I am getting it right to pull the fields like this:

    <?php if (get_field('distributors')): ?>
    		<h3>Where to find <?php the_title(); ?>?</h3>
    		<section class="entry-content clearfix search-results " itemprop="articleBody">
    			<ul>
    				<li><?php the_field('distributors'); ?></li>
    			</ul>
    		</section>
    <?php endif ?>	

    What I would however like is something like this:

    <?php if (get_field('distributors')): ?>
    		<h3>Where to find <?php the_title(); ?>?</h3>
    		<section class="entry-content clearfix search-results " itemprop="articleBody">
    			<select>
    				<?php while (the_field('distributors')): ?>
    					<option><?php the_field('distributors'); ?></option>
    				<?php endwhile; ?>														
    			</select>
    		</section>
    <?php endif ?>

    Despite all of my attempts, I cannot seem to populate this select field.

    Many thanks
    James

  • Managed to solve this like this:

    <?php 
    
    $distributor = get_field('distributors'); ?>
    
    <select>
    	<option value=""></option>
    	<?php foreach ($distributor as $key => $value) {
    		echo "<option name='' id=''>" . $distributor[$key] . "</option>";
    	} ?>
    </select>
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Auto populate a dropdown menu from checkbox field’ is closed to new replies.