• 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 7 years, 2 months ago by H. Adam Lenz.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter H. Adam Lenz

    (@adrock42)

    there is a subsite with the blog id 18 and the tables are there

    Plugin Author Mikko Saari

    (@msaari)

    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

    (@msaari)

    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.