我已经在这里工作了几个晚上,我已经尝试了很多不同的解决方案,宁愿保留PHP而不是jQuery解决方案或AJAX,这是我的代码,由于某种原因,Select Dropdown刚赢了'保持它的价值,任何建议都会令人惊叹。提前谢谢。
<?php
$taxonomy = 'accommodation_area';
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => true
);
$tax_terms = get_terms( $taxonomy, $args );
?>
<select name="<? echo $taxonomy ?>" id="<? echo $taxonomy ?>" class="postform">
<option>Choose Area</option>
<?php if($tax_terms): ?>
<?php foreach ($tax_terms as $tax_term): ?>
<option value="<?php echo $tax_term->slug; ?>" <?php if ( isset( $_POST[ $taxonomy ] ) && ( $_POST[ $taxonomy ] == $tax_term->slug ) ) echo "selected";?>><?php echo $tax_term->name; ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>