Home › Forums › Front-end Issues › Populate select list with values of custom field › Reply To: Populate select list with values of custom field
I’ve been tinkering and finally found something that works:
<form method="get" action="" onchange="submit();">
<div class="input-group">
<?php
global $wpdb;
$meta_key = 'item_oem';
$data = $wpdb->get_results($wpdb->prepare( "SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s", $meta_key) , ARRAY_N ); ?>
<select class="custom-select" id="oems" aria-label="oems" name="item_oem" >
<option selected>Search By OEM</option>
<?php foreach( $data as $value ): ?>
<option value="<?php echo $value[0]; ?>"><?php echo $value[0]; ?> </option>
<?php endforeach; ?>
</select>
<div class="input-group-append">
<a href="/inventory" class="btn btn-secondary" type="button">Clear Filter</a>
</div>
</div>
</form>
I’ll definitely look through your suggestions as well, and see which one works the best.. I don’t want to take a hit on performance just for a filter 🙂
Thank you!
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.