How does the WordPress plugin save data to a database?

Source: Internet
Author: User
Paste the code :? Php // display a sub-menu add_action (admin_menu, my_plugin_menu2) in the WordPress background comment; functionmy_plugin_menu2 () {add_comments_page (data saving, data saving, read, my-unique-identifier, my_plu post the code:
// Display a sub-menu in the WordPress background comment
Add_action ('admin _ menu ', 'My _ plugin_menu2 ');
Function my_plugin_menu2 (){
Add_comments_page ('data save', 'data save', 'read', 'My-unique-identifier', 'My _ plugin_function2 ');
}
Function my_plugin_function2 ()
{
If ($ _ POST ['test _ Den '] = 'y ')
{
Update_option ('test _ input_c ', $ _ POST ['test _ input']);
// Update the database you added
?>
Saved successfully!
}
?>


Add data

Add data here.




}
// Use get_option () to display information in the database.
// The information entered above is included in the wp_options table in the database.
?>

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.