0

I'm creating a site that shows all sites in the network. Each site in the network has a theme customizer where a user enters text. I was able to get the name and url of the site but need to find a way to get the theme option from that site.

This is the code I'm using so far:

<?php $bcount = get_blog_count(); global $wpdb; $blogs = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE spam = '0' AND deleted = '0' and archived = '0' and public='1'"));?>
<?php foreach($blogs as $blog) :?>
<?php if(!(($blog->blog_id == 1)&&($show_main != 1))):?>
    <a href="<?php echo get_blog_details($blog->blog_id)->siteurl; ?>"><?php echo get_blog_details($blog->blog_id)->blogname;?></a>
<?php endif;?>
<?php endforeach;?>

I've also tried get_template_part but that didn't work

<?php echo get_template_part( 'twsa_show_about', get_blog_details($blog->blog_id)->blog_id );?>
2

You will have to switch to your blog using switch_to_blog( $blog->blog_id ); and the access the data you want from that blog.

switch_to_blog( $blog->blog_id );
get_theme_mod('your_key');

This should give you customizer option data for that blog.

Also I'm not sure where you are using this code, but instead of using wpdb query you can use get_sites to get list of your sites.

See: https://developer.wordpress.org/reference/functions/get_sites/

Hope this is what you wanted.

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.