2016-10-25 47 views
0

嗨,我有这个WordPress项目,我的脚本运行良好,并保存到数据库中。我的问题是,当我插入值zipcode 2034并刷新wp-admin页面时,我认为数据正在保存,现在我想输入另一个zipcode 6000,并且第一个输入值正在被新的输入值替换。我怎么能够从中插入另一个值?无需替换保存的数据。这是我下面用表格保存WordPress插件设置

add_action('admin_menu', 'zipcode_menu'); 

function zipcode_menu(){ 
    add_menu_page('Zipcode Page', 'Zipcode', 'manage_options', 'zipcode', 'zipcode'); 
} 

add_action('admin_init', 'update_extra_post_info'); 

function update_extra_post_info() { 
    register_setting('extra-post-info-settings', 'zipcode'); 

} 

function zipcode() { 


    // Now display the settings editing screen 

    echo '<div class="wrap">'; 
    // header 
    echo "<h2>" . __('Zipcode', 'zip') . "</h2>"; 
    // settings form 
    $extra_info = get_option('zipcode'); 
    echo "<pre>"; 
    print_r($extra_info); 
    echo "</pre>"; 

    ?> 

    <form method="post" action="options.php"> 
    <?php settings_fields('extra-post-info-settings'); ?> 
    <?php do_settings_sections('extra-post-info-settings'); ?> 
    <table class="form-table"> 
     <tr valign="top"> 
      <th scope="row">Zipcode:</th> 
      <td><input type="text" name="zipcode" value="<?php echo get_option('zipcode'); ?>"/></td> 
     </tr> 
    </table> 
    <?php submit_button(); ?> 
    </div> 
    <br> 
    <br> 

    <table width="600px"> 
     <tr> 
      <th> 
       Zipcode 
      </th> 
      <th> 
       Options 
      </th> 
     </tr> 
     <tr> 
      <th> 

      </th> 
      <th> 

      </th> 
     </tr> 

    </table> 
    <?php 

} 

代码,我想从数据库中检索所有保存数据到table有人可以帮助我想通了这事了呢?任何帮助都非常明智。 TIA

回答

0

In Wordpress register_setting做表wp_options的登记,所以 它会一直替换你的选项的值。所以我建议创建一个新表,并从这张表中管理你的邮政编码。

+0

ahh好吧所以你的意思是我会创建我自己的表,然后保存即时通讯创建是的数据? –

+0

所以在register_setting这将永远取代价值hmmmm –

+0

感谢这个想法:) –