0

I'm using a Wordpress Multi-site to house a number of sites in one WP install

I'd like to have a nav showing each site with a link to the site.

I'm using this function to do this

        <?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'"));
          if(!empty($blogs)){
              ?>
                <ul class="nav navbar-nav">
                  <li class="portalHome"><a href="dashboard.html">
                  <i class="fa fa-home"></i>
                  <i class="fa fa-chevron-right pull-right chervonMobNav"></i></a></li>
              <?php
              foreach($blogs as $blog){
                  $details = get_blog_details($blog->blog_id);
                  if($details != false){
                      $addr = $details->siteurl;
                      $name = $details->blogname;
                      if(!(($blog->blog_id == 1)&&($show_main != 1))){
                          ?>
                          <li class="menu-item<?php if($counter == get_current_blog_id()){ echo ' current-menu-item';}?>">
                              <a href="<?php echo $addr; ?>"><?php echo $name;?> <i class="fa fa-chevron-right pull-right chervonMobNav"></i></a>
                          </li>
                          <?php
                      }
                  }
              }
              ?></ul><?php
          }
          ?>

It works but I'm also getting an error

        Warning: Missing argument 2 for wpdb::prepare()

What should the second argument be for wpdb::prepare()

ttmt
  • 5,822
  • 27
  • 106
  • 158

1 Answers1

2

$wpdb->prepare is working as sprintf in php

Example from php.net

$num = 5; $location = 'tree';

$format = 'There are %d monkeys in the %s';

echo sprintf($format, $num, $location);

In your query there is no formatting string so you can execute your query like this:

$blogs = $wpdb->get_results("SELECT * FROM $wpdb->blogs WHERE spam = '0' AND deleted = '0' and archived = '0' and public='1'");