Getting started with WordPressget_bloginfo()Enqueuing scriptsMaking network requests with HTTP APIEnqueuing Styleshome_url()Custom Post Typestemplate_includeThe Loop (main WordPress loop)AJAXThe $wpdb ObjectActions and Filterswp_get_current_user()Add/remove contact info for users with user_contactmethods filter hookCreating a custom templateCustomizer Hello WorldCustomizer Basics (Add Panel, Section, Setting, Control)The Admin Bar (aka "The Toolbar")Querying postsAlternating main loop (pre_get_posts filter)ShortcodeCreate a Post Programmaticallyget_template_part()Taxonomiesget_template_part()ShortcodesPost FormatsCustom exerpts with excerpt_length and excerpt_morePlugin developmentSecurity in WordPress - EscapingTemplate hierarchyRemove Version from Wordpress and StylesheetsChild Theme Basicsadd_action()get_template_part()Shortcode with attributeSidebarsSecurity in WordPress - SanitizationinitCreate Template for Custom Post TypeFunction: add_action()Add ShortcodeHow Can I integrate Markdown editor with Advance Custom Field's repeater Add-on.Installation and Configurationwp_get_current_user()WP-CronSecure your installationOptions APIFunction : wp_trim_words()WP_Query() LoopUpdate WordPress ManuallyThemesWP-CLIDebuggingadd_menu_page()add_submenu_page()get_option()get_permalink()get_the_category()the_title()get_the_title()add_editor_style()add_theme_support()WordPress Plugin creationRun WordPress local with XAMPPAdmin Dashboard WidgetsSite MigrationMeta BoxRemove Auto Line Breaks From Content and Excerptget_home_path()Wordpress theme and child-theme developmentREST API

Options API

Other topics

Remarks:

The Options API is a simple and standardized way of working with data staored in the options table of MySQL database. The API makes it easy to create, read, update, and delete options.

get_option

get_option function is used to retrieve a value from from options table based on option name.

You can use the following code to get email address of a WordPress site administrator.

<?php echo get_option('admin_email'); ?>

get_option() has an optional 2nd argument, which allows you to set a default value to return in the case that the requested option isn't set. By default, this argument is false.

To retrieve a text string, and use a boilerplate string if the text isn't set in the options table, you could do this:

<?php get_option( 'my_text', "I don't have anything written. Yet." ); ?>

add_option

add_option function ins used to insert new row into options table.

This will insert a new row in options table with option name some_option_name and value as some_option_value

<?php add_option( 'some_option_name', 'some_option_value' ); ?>

delete_option

delete_option function is used to delete an option from the options table.

This will delete my_custom_option from the options table.

<?php delete_option( 'my_custom_option' ); ?>

update_option

update_option function is used to update a value that already exists in the options table. If the option does not exist, then the option will be added with the option value.

This will set the default comment status to 'closed':

update_option( 'default_comment_status', 'closed' );

Syntax:

  • // Create new option within WordPress
    add_option( $option, $value = , $deprecated = , $autoload = 'yes' );

  • // Removes an option from the database.
    delete_option( $option );

  • // Retrieve a saved option
    get_option( $option, $default = false );

  • // Update the value of an option that was already added.
    update_option( $option, $newvalue );

  • // There are also *_site_option() versions of these functions,
    // to manipulate network-wide options in WordPress Multisite

  • // Create new network option
    add_site_option( $option, $value = , $deprecated = , $autoload = 'yes' );

  • // Removes a network option
    delete_site_option( $option );

  • // Retrieve a saved network option
    get_site_option( $option, $default = false );

  • // Update the value of an option that was already added.
    update_site_option( $option, $newvalue );

Contributors

Topic Id: 7854

Example Ids: 25545,25603,25604,25605

This site is not affiliated with any of the contributors.