0
存在一個問題,即保存在元框內的複選框沒有保存。我可以保存一個值並讓它返回複選框的值,而不是多個值,我需要這些值。我已經嘗試添加一個foreach循環到update_post_meta代碼,但它不起作用。對我出錯的地方略有困惑。Wordpress保存元框複選框選擇
複選框代碼是:
$areas = $wpdb->get_results("SELECT * FROM locations ORDER BY locationName ASC");
if(count($areas)) :
?>
<div id="locationAssignedBoxes" size="1">
<?php
foreach($areas as $area) :
?>
<input type="checkbox" id="locationAssigned" name="locationAssigned" value="<?php echo $area->id; ?>"<?php if(get_post_meta($post->ID, 'locationAssigned', true) == $area->id) { ?> checked="checked"<?php } ?> /> <?php echo $area->locationName; ?><br>
<?php
endforeach;
?>
</div>
<?php
endif;
?>
Update_post_meta代碼:
update_post_meta($post->ID, 'locationAssigned', $_POST['locationAssigned']);
非常感謝!