lundi 2 mars 2015

Save data on custom table Wordpress


Here is my current code,



<div class="wrap">
<div id="icon-tools" class="icon32"></div>
<h2>Quote Manager</h2>
<div class="aio-content">
<form method="post" action="options.php">
<?php settings_fields( 'mgg_aio_quote_manager_setting' ); ?>
<?php do_settings_sections( 'mgg_aio_quote_manager_setting' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">Test</th>
<td><input type="text" name="mgg_aio_quote_manager_setting_n" value="<?php echo get_option( 'mgg_aio_quote_manager_setting_n' ); ?>"/></td>
</tr>
</table>
<?php submit_button(); ?>



</div>
</div>

function mgg_aio_register_setting() {
register_setting( 'mgg_aio_quote_manager_setting', 'mgg_aio_quote_manager_setting_n' );
}


add_action( 'admin_init', 'mgg_aio_register_setting' );


Everything works fine and my data gets saved under wp_options


My question is how could i make a custom table alongside wp_options and add all my plugin's options into it ?


My plugin is not under options page and has it's own top level page. The custom table should use prefix from wp-config. ({$wpdb->prefix})


Can anyone guide me here ? Is there any code available which I can include in my plugin to make it easier for writing and reading from db ?





Aucun commentaire:

Enregistrer un commentaire