views:

162

answers:

4

Where does $wpdb->options come from?

I can't see $wpdb-options() function or $this->options so how is this achieved?

A: 

$wpdb->options is a property of the object $wpdb (which is an instance of the class wpdb).

It's value is the name of the options table in the database, usually wp_options.

TheDeadMedic
So where is $wpdb->options defined?
Yikes
I seee, thanks :)
Yikes
Do you know where it is defined?
Yikes
It's set in the class `wpdb` inside the `wp-includes/wp-db.php`.
TheDeadMedic
Theres actually a loop inwhich its set: foreach ( (array) $this->tables as $table ) $this->$table = $this->prefix . $table;
Yikes
A: 

"wpdb" is class to interact with database. Its in "wp-db.php". since i don't know what exactly you are asking about this link might be helpful for you.

Rojan
Yeh but I don't understand where the $wpdb->options come from (the options bit)
Yikes
A: 

I think people are struggling to understand your question. Maybe provide a bit more detail or context.

If you are asking where the options originally came from, then the answer is that they are set during setup and in the WP Admin pages. They are then stored in the wp_options table in your database, and retrieved into the $wpdb->options variable that is a member of the $wpdb object when Wordpress loads.

Greg
Yeh but where is $wpdb-options in the files? Where is it defined, not what it does but where is it?
Yikes
Oh, you probably won't find a single spot where all the options are defined. Each option has a key (string) and a value. Different places in the code will query the DB for the value associated with a particular key. There is a function "get_option" in "functions.php" for doing this. It queries the table name specified by $wpdb->options. Note that plugins also use the wp_options table to store stuff.
Greg
How could I achieve the same thing?
Yikes
I see get_option, I just wondered where $wpdb->options came from
Yikes
+2  A: 

Okay, here is a complete clarification of the confusion I can see here.

$wpdb is an object for querying the database. The $wpdb->options property is merely the name of the options table in the database. It does not store nor contain the contents of that table.

WordPress options (or settings) are stored, updated and read using the functions add_option(), update_option() and get_option() respectively.

You can also get all options using get_alloptions().

The reason you should use $wpdb properties to reference tables in your SQL queries is that the table prefix is user defined, and you cannot assume it will always be called 'wp_tablename'.

TheDeadMedic