Web Design
Mobile Internet
Brand Design
Innovative
News
Encyclopedias

WordPress Plug in Making Tutorial: Saving Data to Database

Date:2013-05-06 Source: Shangpin China Type: website encyclopedia
Word Size: small   medium   big

Beijing website construction Shangpin China (www.sino web. net): This article explains how to save the data in the database and display it on the page. The content in the input box will not disappear when the form is submitted. To realize this function, we need to use the WordPress function. Next, we will explain the specific implementation method, and paste the code first. According to the previous plug-in example, you can directly modify it.

<? php

//Display a submenu in WordPress background comments

add_action('admin_menu', 'my_plugin_menu2');

function my_plugin_menu2() {

Add_comments_page ('data saving ',' data saving ',' read ',' my unique identifier ',' my_plugin_function2 ');

}

function my_plugin_function2()

{

if($_POST['test_hidden'] == 'y')

{

update_option('test_input_c',$_POST['test_input']);

//Update the database you added

?>

<div id="message" class="updated">Saved successfully</ div>

<? php

}

?>

<div class="wrap">

<? php screen_icon(); // Display icon?>

<h2>Add Data</h2>

<p>Add data here</ p>

<form action="" method="post" id="my_plugin_test_form">

<h3>

<label for="test_input">Test data:</label>

<input type="text" id="test_input" name="test_input" value="<?php echo esc_attr(get_option('test_input_c')); ?>" />

<h3>

<p>

<input type="submit" name="submit" value="Save"/>

<input type="hidden" name="test_hidden" value="y" />

</p>

</form>

</div>

<? php

}

//The information stored in the database is displayed through get_option().

//The above information is stored in the wp_options table in the database.

?>

The above short code implements the function of saving and displaying data. Through this function, we can extend to other methods or functions. For example, some good themes have theme settings, and some of the display and storage can be achieved using the above methods, so you can try more. The approximate effect is shown in the following example.

 WordPress Plug in Making Tutorial: Saving Data to Database

Well, that's all for this article. If you don't understand or have good suggestions, please ask questions and guide.
This article was published by Beijing Website Construction Company Shangpin China //ihucc.com/


Please contact our consultant

+86 10-60259772

Please provide your contact number. The project manager of shangpin China will contact you as soon as possible.