WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Feb 22 2011

How to Get an Array of Options Tables from WordPress Multisite, get_ms_options_tables()

This simple function will return an array of the various WordPress multisite options table names that exist in the WordPress database. For example, this function will return an array that looks like:

Array
(
[0] => wp_options
[1] => wp_2_options
[2] => wp_3_options
[3] => wp_6_options
[4] => wp_9_options
[5] => wp_11_options
[6] => wp_12_options
[7] => wp_14_options
[8] => wp_17_options
[9] => wp_19_options
)

[php]function get_ms_options_tables() {
global $wpdb;
$query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";
$query .= " ORDER BY {$wpdb->blogs}.blog_id ";
$order = "ASC";
$query .= $order;
$sql = $wpdb->prepare($query);
$blogs = $wpdb->get_results( $sql, ARRAY_A );
//$blogs = $this->get_ms_sites();
foreach ($blogs as $blog) {
$tables[] = $wpdb->get_blog_prefix($blog['blog_id']).'options';
}
return $tables;
}[/php]

Written by Travis Smith · Categorized: Tutorials

StudioPress Premium WordPress Themes     WP Engine Managed WordPress Hosting

What can I do for you!?

Custom Development

We develop plugins by determining both business/functional and technical requirements, following WordPress development best practices, and using agile methodology to ensure you get the best solution.

Consulting

Have questions? Need a reliable developer to consult? Please contact us today!

Customized Theme

We can customize your theme or child theme, or create a child theme for you based on your needs while enhancing the performance of every individual attribute.

Customized Plugin

We can customize your plugins, extend plugins (e.g., Gravity Forms, Jetpack, Soliloquy) based on your needs ensuring security, performance, and positive business impact.

Contact Us

About Travis Smith

As a WordPress enthusiast, developer, and speaker, Travis writes about what he learns in WordPress trying to help other WordPress travelers, beginners and enthusiasts with tutorials, explanations, & demonstrations.

Comments

  1. Nicolae Gabriel says

    August 2, 2011 at 6:32 am

    These are all the options :

    $all_options = wp_load_alloptions();

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

Copyright © 2025 � WP Smith on Genesis on Genesis Framework � WordPress � Log in