0

I need to call the WordPress options table and pull some data. However, the table name may be different (typically wp_options) depending on whether the default table prefix was used on installation.

How can I obtain a reference to the site's table prefix in order to properly access the site's options table via $wpdb?

/**
 * WordPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each a unique
 * prefix. Only numbers, letters, and underscores please!
 */
$table_prefix  = 'wp_';
5
global $wpdb;
$prefix = $wpdb->prefix;
  • +1, I believe this is correct. I've since found that I need to call the options table with $wpdb->options rather than wp_options, which resolves my issue without needing the prefix. – N2Mystic Feb 13 '12 at 21:11
0

While you can get the prefix with $wpdb->prefix, as suggested by Pippin, you're much better off getting the table you need directly with $wpdb->options (in your case). $wpdb includes, by default, the table names for every table, accessible by $wpdb->{table_name}. For example: the posts table is $wpdb->posts...pretty straightforward stuff really.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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