我想同時更新多個職位後元。我有以下查詢:wordpress更新多個職位後元meta
<form action="" method="post">
<?php
$variations = new WP_Query();
$variations->query(array('showposts' => -1, 'post_type' => 'product_variation')); while ($variations->have_posts()) : $variations->the_post(); ?>
<input name="regular_price[]" type="text" value="<?php echo get_post_meta(get_the_id(), "_regular_price", true); ?>" />
<input name="sale_price[]" type="text" value="<?php echo get_post_meta(get_the_id(), "_sale_price", true); ?>" />
<input name="item_id[]" type="hidden" value="<?php echo get_the_id(); ?>" />
<?php endwhile; wp_reset_query();?>
<input name="save" type="submit" />
然後我有以下的PHP來處理數據:
<?php
if (isset($_POST['save'])) {
$ids = $_POST['item_id'];
$sales = $_POST['sale_price'];
foreach ($ids as $id){
update_post_meta($id,'_sale_price',$sale));
}
} ?>
出於某種原因,上述方法不正確保存。它只會保存最後一個值,並將其應用於所有後期元。有什麼我做錯了嗎?
@StreetCoder這是爲什麼? – danyo
對不起,我錯過了,但我正在尋找解決方案 – StreetCoder