【问题标题】:wordpress update multiple posts in one querywordpress 在一个查询中更新多个帖子
【发布时间】:2013-12-11 01:26:42
【问题描述】:

我目前有一个循环自定义帖子类型的表单,列出所有帖子,如下所示:

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

我想保存在一个查询中所做的所有更改(一个保存按钮,这将保存所有更改)。解决这个问题的最佳方法是什么?我正在循环这样的结果:

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

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

           echo $price;

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

} ?>

但我正在努力将帖子的 id 放入该 foreach 中。然后我想使用update_post_meta 函数更新所有帖子。

非常感谢任何能帮助我指明正确方向的人。

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    您需要在末尾添加一个唯一标识符/id

    $_POST['send_to']
    

    类似这样的东西,其中 $id = 独特的东西,例如产品 ID:

    $_POST['send_to'][$id]
    

    【讨论】:

      猜你喜欢
      • 2013-12-10
      • 2013-12-11
      • 1970-01-01
      • 2015-03-13
      • 1970-01-01
      • 2016-07-05
      • 2021-09-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多