douqianbiao4216 2013-11-21 16:59
浏览 24
已采纳

wordpress在一个查询中更新多个帖子

I currently have a form which loops through a custom post type, listing out all posts like this:

<form action="" method="post">   
<table width="100%" border="0">
  <tr>
    <td><strong>Variation</strong></td>
    <td><strong>Price</strong></td>
    <td><strong>Sale Price</strong></td>
   <?php if(is_plugin_active($wwp) ) { echo '<td><strong>Wholesale Price</strong></td>'; } ?>
  </tr>

<?php query_posts(array('showposts' => -1, 'post_type' => 'product_variation', /*remove'year'=> date("Y"),*/ )); while (have_posts()) : the_post(); ?>
  <tr>
    <td><?php the_title(); ?></td>
    <td><input name="regular_price[]" type="text" value="<?php echo get_post_meta(get_the_id(), "_regular_price", true); ?>" /></td>
    <td><input name="sale_price[]" type="text" value="<?php echo get_post_meta(get_the_id(), "_sale_price", true); ?>" /></td>
    <?php if(is_plugin_active($wwp)){echo '<td><input name="wholesale_price[]" type="text" value="'.get_post_meta(get_the_id(), "_wholesale_price", true).'" /></td>';}?>
    <input name="item_id[]" type="hidden" value="<?php echo get_the_id(); ?>" />

  </tr>
<?php endwhile; wp_reset_query();?> 


  <tr>
    <td align="left"><br /><input name="save" type="submit" /></td>
    <td></td>
    <td></td>
   <td></td>
  </tr>

 </table> 
</form>

I would like to save all changes made within one query (one save button, and this will save all changes). What is the best way to approach this? I am looping through the results like this:

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

    foreach ($_POST['wholesale_price'] as $price{

           echo $price;

        //update_post_meta($ids,'_wholesale_price',$_POST['send_to']);
    };

} ?>

But i am struggling to get to get the id of the post into that foreach. I would then like to update all posts using the update_post_meta function.

Any help to point me in the right direction is greatly appreciated.

  • 写回答

1条回答 默认 最新

  • douluo1330 2013-12-10 17:26
    关注

    You will need to add a unique identifier / id to the end of

    $_POST['send_to']
    

    Something like this where $id = something unique for instance product id:

    $_POST['send_to'][$id]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊