WordPress $wpdb->options

Where does $wpdb->options come from?

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

Related posts

Leave a Reply

5 comments

  1. 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’.

  2. $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.

  3. $wpdb->options is defined through wp_set_wpdb_vars() in wp-includes/load.php.

    This line sets the table names via a call to the set_prefix function:

    $prefix = $wpdb->set_prefix( $table_prefix );
    

    Hope this helps!

  4. 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.