Title: Saving Plugin Preference
Last modified: August 19, 2016

---

# Saving Plugin Preference

 *  [sumone4life](https://wordpress.org/support/users/sumone4life/)
 * (@sumone4life)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/saving-plugin-preference/)
 * Hello,
 * I am making a plugin that needs to save preferences based on the post its attached
   with. I assume that i need to write the settings to the database so that they
   can be retrieved later.
 * Is there an easy way to do this?

Viewing 1 replies (of 1 total)

 *  [WatchCount.com](https://wordpress.org/support/users/watchcountcom/)
 * (@watchcountcom)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/saving-plugin-preference/#post-1288340)
 * Yes, there definitely is. When I first needed to (learn to) do the same thing,
   I was a little worried I would need to brush up on mysql commmands. Then I found
   that there was a layer of abstration that WordPress introduced to make it easier
   to write to the DB – something like the $wpdb class (in PHP) that gave easy access
   to the DB.
 * **Then** I discovered that they made it _even easier_ for reading/writing/saving
   plugin preferences to the WPDB without even needing to use objects/classes/etc.
   Just a simple function, [get_option()](http://codex.wordpress.org/Function_Reference/get_option),
   retrieves options from the WP DB that you wrote with update_option(). The format
   is pretty much a simple name-value pair.
 * As you learn about and play with these functions, here are 3 tips for good implementation:
 * 1) update_option() is great for both adding a new option, and updating one – 
   usually no need to bother with the add_option() function at all.
 * 2) Instead of writing many options to the DB for all of your plugin’s settings,
   store all of your settings in 1 array, then store that 1 array as 1 simple option
   in the WP DB.
 * 3) When your plugin is uninstalled/deleted, run delete_option() to remove the
   option(s) from the WP DB.
 * -WCC

Viewing 1 replies (of 1 total)

 The topic ‘Saving Plugin Preference’ is closed to new replies.

 * 1 reply
 * 2 participants
 * Last reply from: [WatchCount.com](https://wordpress.org/support/users/watchcountcom/)
 * Last activity: [16 years, 10 months ago](https://wordpress.org/support/topic/saving-plugin-preference/#post-1288340)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
