Multisite – Retrieve the same theme option from all sites of the network

I’m running multisite with each subsite using the same custom theme. I’m using NHP Options for logo upload and contact page info changes in that theme.

I’d like to add a site list page to the main site (which is using a different theme) and have each subsites logo be displayed beside its name in the list.

Getting the site list was fine – no problems there, but for the life of me I can’t figure out how to get the logos to show.

The data is stored in a serialized array in each sites options table – with the option_name of ‘nhp_opts’.

The data looks like this :

    a:5:{s:8:"last_tab";s:1:"0";i:19;s:59:"http://_PATH_TO_LOGO.png";i:20;
    s:34:"Test Street,Testing,Co. Test";i:21;s:16:"(000) 123 456789";s:10:"multi_text";
    a:4:{i:0;s:21:"Mon - Fri 9.30 - 6.00";i:1;s:18:"Sat - 10.00 - 6.00";
    i:2;s:18:"Sun - 12.00 - 5.00";i:3;s:22:"Bank Holidays - Closed";}}

and the code I cobbled together is this:

    <?php global $wpdb;
            $logos = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->options WHERE option_name = nhp_opts  "));
                foreach($logos as $logo){
                $thedata = $logos;
                $thedata = unserialize($thedata);
                echo $thedata;

                }?>

All I get is Array() – repeated a bunch of times.

I’m not very familiar with working directly with the database – so I’m not overly surprised this didn’t work!

I’ve spent a few days now puzzling this one out – any help at all would be greatly appreciated! Thanks!

2 Answers
2

may be its a late reply, but i hope this code will help you and anothers to solve this problem.

 <?php
  global $wpdb;
  $blogs = $wpdb->get_results("SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0' AND blog_id != 1 ");

  $sites = array();

 foreach ($blogs as $blog) {

 $sites[$blog->blog_id] = get_blog_option($blog->blog_id, 'nhp_opts');

}
  ?>

now you can use img tag and loop through this to get your option, for a purpose the current site option is omitted from sql, if you want to include current site in your result as well you can ignore AND blog_id != 1 this line from sql.

I hope this will help others as well.

Leave a Comment