2013-11-26 4 views
1

나는 여러 게시물을 동시에 게시 메타를 업데이 트하려고합니다. 나는 다음과 같은 쿼리를 가지고 :wordpress 여러 게시물을 게시 메타 게시

<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)); 

} 
} ?> 

합니다. 마지막 값만 저장하고 모든 게시물 메타에 적용합니다. 내가 뭘 잘못하고 있니?

+0

@StreetCoder 왜 그런가요? – danyo

+0

미안하지만, 나는 그것을 놓쳤다. 해결책을 찾고있다. – StreetCoder

답변

3

update_post_meta 필드에 $sale에 ID를 추가해야한다고 생각합니다. 이와 같이 :

<?php 
if (isset($_POST['save'])) { 

    $ids = $_POST['item_id']; 
    $sales = $_POST['sale_price']; 

foreach ($ids as $id){ 

    update_post_meta($id,'_sale_price',$sale[$id])); 

} 
} ?> 
0

"for"을 (를) 잊었습니다.

update .......; 
} 
} 
+0

미안하다. .... 질문이 수정되었습니다. – danyo

0

대요. 나는 $count으로 문제가 있다고 생각합니다. 루프에서 데이터를 업데이트하려면이 변수에 적절한 카운트 값이 있는지 확인하십시오.

+0

$ count = $ variations-> post_count; – danyo