Title: Errors when using &#8220;searchblogs&#8221;
Last modified: September 20, 2017

---

# Errors when using “searchblogs”

 *  [H. Adam Lenz](https://wordpress.org/support/users/adrock42/)
 * (@adrock42)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/errors-when-using-searchblogs/)
 * Whenever i use searchblogs to search more than one subsite I get an error
 *     ```
       WordPress database error Unknown column 'wp_postmeta.post_id' in 'where clause' for query SELECT COUNT(DISTINCT(doc)) FROM wp_relevanssi AS relevanssi WHERE  term = 'major'   AND ((relevanssi.doc IN (SELECT DISTINCT(posts.ID) FROM wp_posts AS posts
       WHERE posts.post_type NOT IN ('revision', 'nav_menu_item', 'custom_css', 'customize_changeset', 'acf-field-group', 'acf-field', 'mod_clone', 'bu_link'))) OR (relevanssi.doc = -1)) AND ( wp_postmeta.post_id IS NULL) 
       ```
   
 * `made by require('wp-blog-header.php'), require_once('wp-includes/template-loader.
   php'), include('/plugins/ncfgears-search/templates/template-search.php'), relevanssi_do_query,
   relevanssi_search_multi, QM_DB->query`
 * for each blog id in the searchblogs query var so if that var is 1,5,10 I would
   get this same error and the only difference is
 *     ```
       wp_postmeta.post_id
       wp_5_postmeta.post_id
       wp_10_postmeta.post_id
       ```
   
 * So I used the filter `relevanssi_query_filter` which is right near where the 
   error is to output the query. it looks like
 *     ```
       SELECT *, title + content + comment + tag + link + author + category + excerpt + taxonomy + customfield AS tf
       FROM wp_18_relevanssi AS relevanssi  LEFT JOIN wp_18_postmeta ON (relevanssi.doc = wp_18_postmeta.post_id AND wp_18_postmeta.meta_key = 'exclude_local_search' ) WHERE (term LIKE '%major' OR term LIKE 'major%')   AND ((relevanssi.doc IN (SELECT DISTINCT(posts.ID) FROM wp_18_posts AS posts
       WHERE posts.post_type NOT IN ('revision', 'nav_menu_item', 'custom_css', 'customize_changeset', 'acf-field-group', 'acf-field', 'mod_clone', 'bu_link'))) OR (relevanssi.doc = -1)) AND ( wp_18_postmeta.post_id IS NULL) ORDER BY tf DESC LIMIT 100
       ```
   
 * and it runs in phpMyAdmin and returns good data. In fact, this runs on the front
   end, it just throws an error and is clogging up my php error log.
    -  This topic was modified 8 years, 6 months ago by [H. Adam Lenz](https://wordpress.org/support/users/adrock42/).

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [H. Adam Lenz](https://wordpress.org/support/users/adrock42/)
 * (@adrock42)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/errors-when-using-searchblogs/#post-9513622)
 * there is a subsite with the blog id 18 and the tables are there
 *  Plugin Author [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * (@msaari)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/errors-when-using-searchblogs/#post-9515768)
 * Looks like I can reproduce this error on my site. The two queries that fail do
   not introduce the wp_postmeta table at all, that’s why the column is unknown.
   At least one of those columns should not use the postmeta parameter at all… Hmm,
   have to investigate this.
 *  Plugin Author [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * (@msaari)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/errors-when-using-searchblogs/#post-9515948)
 * Ok, I think I got it now.
 * In lib/premium_features.php, find this line:
 * `$query = "SELECT COUNT(DISTINCT(doc)) FROM $relevanssi_table AS relevanssi WHERE
   $term_cond $query_restrictions";`
 * and change it to
 * `$query = "SELECT COUNT(DISTINCT(doc)) FROM $relevanssi_table AS relevanssi $
   query_join WHERE $term_cond $query_restrictions";`
 * Also find this line:
 * `$query = "SELECT COUNT(DISTINCT(doc)) FROM $relevanssi_table AS relevanssi`
 * and change it to:
 * `$query = "SELECT COUNT(DISTINCT(doc)) FROM $relevanssi_table AS relevanssi $
   query_join`
 * That should get rid of the errors.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Errors when using “searchblogs”’ is closed to new replies.

 * ![](https://ps.w.org/relevanssi/assets/icon-256x256.png?rev=2025044)
 * [Relevanssi - A Better Search](https://wordpress.org/plugins/relevanssi/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/relevanssi/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/relevanssi/)
 * [Active Topics](https://wordpress.org/support/plugin/relevanssi/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/relevanssi/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/relevanssi/reviews/)

## Tags

 * [database](https://wordpress.org/support/topic-tag/database/)
 * [MySQL](https://wordpress.org/support/topic-tag/mysql/)

 * 3 replies
 * 2 participants
 * Last reply from: [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * Last activity: [8 years, 6 months ago](https://wordpress.org/support/topic/errors-when-using-searchblogs/#post-9515948)
 * Status: not resolved