I want show drop down value In wordpress

enter image description here

I am working on this drop down code. every thing is good problem is that I am not able to bind this query , when course is selected then address is automatically show in option box.

<select  name="event_id_dropdown" id="event_id_dropdown" data-settings='{"cutOff": 5}'  class="location-select dropdown" required>
<option value="">Select Course</option>
<?php $args=array('post_type'=>'course', 'posts_per_page'=>'-1','post__not_in' => array(1439 ));
$the_query = new WP_Query( $args );     
$sr = 1; 
if($the_query->have_posts() ) : 
while ( $the_query->have_posts() ) : $the_query->the_post();
$chkid =  get_the_ID();
$chktitle = get_the_title();
if($chkid == $_POST['event_id_dropdown'])
echo '<option value="'.$chkid.'" selected>'.$sr.'.'.$chktitle.'</option>';
                                                        else                                    
echo '<option value="'.$chkid.'">'.$sr.'.'.$chktitle.'</option>';   
$sr++;       
endwhile; 
 wp_reset_postdata(); 
endif;
?>
</select>
</div>
</div>
<span class="drop-error error"></span> 
</div> 

  <!-- Here div is closed for address  right now other is started<!-->


  <div class="location-select-container">
    <div class="select-facade" style="overflow:visible;">
    <select  name="event_id_dropdown-a" id="event_id_dropdown" data-settings='{"cutOff": 5}' class="location-select dropdown" required>
    <option value="">Select Address</option>
    <?php 
    global $wpdb;
    $results = $wpdb->get_results( 'SELECT DISTINCT  short_description FROM event_cource ORDER BY event_cource_id', OBJECT );
    foreach($results as $result){
    $chktitle=$result->short_description;
    $chkid=$result->event_cource_id;

    if($chkid == $_POST['event_id_dropdown-a'])
    echo '<option value="'.$chkid.'" selected>'.$chktitle.'</option>';
                                                            else                                    
    echo '<option value="'.$chkid.'">'.$chktitle.'</option>';   
    }
    ?>
    </select>

    </div>

Read more here: I want show drop down value In wordpress

Leave a Reply

Your email address will not be published. Required fields are marked *