WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In a WP_List_Table example I'm using, I am seeing how to make a general query to the wp_options table in the Wordpress database.

For example, $query = "SELECT * FROM $wpdb->options";

I also see that we typically create a foreach loop to display all the records in this table on separate rows. Sounds easy enough.

But I would like to filter this query to reference an "options array" instead. This is a single value in my table. For example, I want to query a single option called testimonial_settings and then retrieve all the array values from this single field. I can't wrap my head around how I would do this using a foreach loop.

Maybe a simple example showing the proper syntax would help clear things up....?

share|improve this question
up vote 3 down vote accepted

The table wp_options can normally be queried using get_option()

So you can use something like

$testimonial_settings = get_option('testimonial_settings');

to retrieve the values of testimonial_settings. If the stored value is serialized, it will be retrieved as an array.

share|improve this answer
So WP_List_Table does not care "how" we access the options, right? That's great! None of the WP_List_Table examples out there are using get_option('blah') to access settings. I have only seen database query methods. – Rob Myrick Dec 17 '12 at 15:00
It just depends what you want to do. If you're having a plugin having lots of settings, it is recommended to use a single entry in the wp_options table and store your data as an array. Storing each settings in its own field can result in more queries to fetch your data. It gets worse if autoload is set to true. – RRikesh Dec 18 '12 at 4:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.