So we currently have a drop down option that auto populates from custom post types and displays for the customer to choose from.
However, now their list is extremely long so they would like the functionality of being able to start typing a company name to reduce the amount of results in the list, but i’m completely stuck and need help converting our current option to the desired result.
<div class="custom-control__wrap">
<i class="fas fa-caret-down"></i>
<select data-field-name="customer" class="form-control validate[required] autosaveFieldDropdown" name="customer" id="customer">
<option value="" selected>Company name</option>
<?php
$args = array(
'post_type' => 'companies',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC'
);
$posts = get_posts($args);
?>
<?php foreach ($posts as $post): ?>
<option value="<?php echo $post->ID; ?>" <?php echo ($personalInfoNameObj->customer == $post->ID) ? 'selected="selected"' : '';?> ><?php echo $post->post_title ; ?></option>
<?php endforeach; ?>
</select>
</div>
Any help is greatly appreciated
2
Answers
Ended up using a WP Query with a while loop pushing into a datalist to get the desired result.
Use below code it will work properly.