Get_option () in WordPress tutorial ()

Source: Internet
Author: User
Tags wordpress database wordpress blog
Functions of the get_option Function

If you wantDevelop your own WordPress pluginYou may want to save some data. The custom data is stored in the wp_options table of the WordPress database. The wp_options table is like a big drawer. Your WordPress settings, and the custom data of your WordPress plug-in are all inserted in the wp_options table. If you like to directly read the WordPress database, the get_option () function will be useless, but if you want your WordPress code to be compatible with the future, or you do not want your single. PHP and so on. If the source code is too large and the logic is responsible, or you want your WordPress plugin to be used by more users who do not use PHP or MySQL, use the get_option () that comes with WordPress () functions are more secure and convenient. Of course, the use of the WordPress get_option function and the plug-in mechanism has a slight impact on the speed of WordPress. The pros and cons of this function are weighed by the hacker himself.

After talking about the wp_options table of so many WordPress databases, I hope you will have a better understanding of get_option. The following describes how to use the get_option function:

Format of the get_option function:

<?php echo get_option($showwhat); ?>

Or

<?php echo get_option(“showwhat”); ?>

Here $ showwhat can be a lot of things. Find the wp_options table. The following is an example:

<?php echo get_option(“blog_charset");?> // Get the character set of your blog

<? PHP $ admin_email = get_option ('admin _ email ');?> // Obtain the email of your blog. What is the purpose? For example, if someone posts a message to himself.

......

Note that the previously used get_settings () function in WordPress is replaced by the current get_option () function.

The get_option () function is a function that we often use when integrating background functions. It is mainly used to obtain the desired field content from the option table of the Wordpress blog database, in most of the current themes, as long as the theme is integrated with the background control page, most of them use this function. Although Wp has given us a lot of ways to temporarily store our settings for the theme, however, using a stable database to store theme settings is still the first choice for most topic authors.

Get_option () functionThere are still a lot of Chinese literature on the Internet, including the official documentation. This function also has a Chinese version, because it is easy to use and has a clear idea, so there is no more explanation here.
Official API: get_option
Direct memo usage

Tips

We usually add a judgment when taking the settings, because we do not know whether the topic is installed in the system for the first time,

If (! Get_option ('xiangzi') {// determine whether $ default_xiangzi = array exists (// first set a default value 'title' => 'zibo website builder ', 'name' => 'cao Yongquan ', 'url' => '2017. org '); update_option ('caoyongquan', $ default_xiangzi );
// Set the default value of option} $ Xiangzi = get_option ('caoyongquan '); // get the setting


Unfortunately, for some reason, WP officially added the second parameter of the get_option function to us.
So we can.

$ Default_xiangzi = array (// first set a default value 'title' => 'zibo website builder', 'name' => 'cao Yongquan ', 'url' => '123. org ') $ Xiangzi = get_option ('xiangzi', $ default_xiangzi );
// Is this simple?

Get_option () in WordPress tutorial ()

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.