Support » Plugin: Relevanssi - A Better Search » Receiving an error on some queries

  • Resolved track77

    (@track77)


    I’m receiving the next error on some queries like “?s=pro&product_cat=plugins&product-types=3ds-max-asset-tracking”

    WordPress database error Unknown column 'Array' in 'where clause' for query SELECT term_taxonomy_id
    					FROM w_p_term_taxonomy
    					WHERE term_id = Array AND taxonomy = '' made by require('wp-blog-header.php'), wp, WP->main, WP->query_posts, WP_Query->query, WP_Query->get_posts, apply_filters_ref_array, WP_Hook->apply_filters, relevanssi_query, relevanssi_do_query, relevanssi_search, relevanssi_get_term_tax_id

    I fixed this by adding next code to search.php file

    /* fix $term_tax_id */
    if( is_array( $row['taxonomy'] ) ||  !is_array ( $term_tax_id ) ) {
    	if( !is_array ( $term_tax_id ) ) {
    		$term_tax_id = explode( ',', $term_tax_id );
    		$term_id = $term_tax_id;
    	}
    }
    /* Check for wp error */
    if( ! is_wp_error( $kids ) )
    foreach ($kids as $kid) {
    	$term = get_term_by('id', $kid, $row['taxonomy']);
    	$term_tax_id[] = relevanssi_get_term_tax_id('id', $kid, $row['taxonomy']);
    }

    Will be cool if you add this fix to code.
    PS. this query is generated by Product Filter plugin
    https://codecanyon.net/item/woocommerce-product-filter/8514038

    • This topic was modified 2 years, 2 months ago by  track77.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Thanks, but I’d need a bit more detail here. Looks like your code just sweeps the problem under the rug, but doesn’t also remove the taxonomy filter – and that doesn’t sound like a good thing.

    I’d really need to see the complete tax_query object this plugin is passing to Relevanssi. What is inside that array, where is the taxonomy information stored since that’s left empty and so on.

    So, on line 88, before this line:

    if (is_array($tax_query)) {

    What does

    var_dump($tax_query);

    print out?

    [30-Jul-2017 10:32:33 UTC] Array
    (
    [0] => Array
    (
    [taxonomy] => product_cat
    [field] => slug
    [terms] => Array
    (
    [0] => plugins
    )

    [include_children] => 1
    [operator] => IN
    )

    [1] => Array
    (
    [taxonomy] => product-types
    [field] => slug
    [terms] => Array
    (
    [0] => 3ds-max-asset-tracking
    )

    [include_children] => 1
    [operator] => IN
    )

    [2] => Array
    (
    [relation] => AND
    [0] => Array
    (
    [taxonomy] => product_visibility
    [field] => slug
    [terms] => Array
    (
    [0] => outofstock
    )

    [operator] => NOT IN
    )

    [1] => Array
    (
    [taxonomy] => product_visibility
    [field] => slug
    [terms] => Array
    (
    [0] => exclude-from-search
    )

    [operator] => NOT IN
    )

    )

    )

    [30-Jul-2017 10:32:33 UTC] WordPress database error Unknown column ‘Array’ in ‘where clause’ for query SELECT term_taxonomy_id
    FROM wp_term_taxonomy
    WHERE term_id = Array AND taxonomy = ” made by require(‘D:\My Documents\My Web Sites\3ddkstudio.com\wp-blog-header.php’), wp, WP->main, WP->query_posts, WP_Query->query, WP_Query->get_posts, apply_filters_ref_array, WP_Hook->apply_filters, relevanssi_query, relevanssi_do_query, relevanssi_search, relevanssi_get_term_tax_id

    [30-Jul-2017 10:32:33 UTC] PHP Fatal error: Uncaught Error: [] operator not supported for strings in D:\My Documents\My Web Sites\3ddkstudio.com\wp-content\plugins\relevanssi\lib\search.php:237
    Stack trace:
    #0 D:\My Documents\My Web Sites\3ddkstudio.com\wp-content\plugins\relevanssi\lib\search.php(1320): relevanssi_search(Array)
    #1 D:\My Documents\My Web Sites\3ddkstudio.com\wp-content\plugins\relevanssi\lib\search.php(49): relevanssi_do_query(Object(WP_Query))
    #2 D:\My Documents\My Web Sites\3ddkstudio.com\wp-includes\class-wp-hook.php(300): relevanssi_query(Array)
    #3 D:\My Documents\My Web Sites\3ddkstudio.com\wp-includes\plugin.php(244): WP_Hook->apply_filters(Array, Array)
    #4 D:\My Documents\My Web Sites\3ddkstudio.com\wp-includes\class-wp-query.php(3007): apply_filters_ref_array(‘the_posts’, Array)
    #5 D:\My Documents\My Web Sites\3ddkstudio.com\wp-includes\class-wp-query.php(3248): WP_Query->get_posts()
    #6 D:\My Documents\My Web Sites\3ddkstudio.com\wp-includes\class-wp.php(617): WP_Query->query(Array)
    #7 D:\My Documents\My Web Sites\3ddkstudio.co in D:\My Documents\My Web Sites\3ddkstudio.com\wp-content\plugins\relevanssi\lib\search.php on line 237

    Plugin Author Mikko Saari

    (@msaari)

    If you add

    if (empty($term_tax_id)) $term_tax_id = array();

    before the line

    if (isset($term_id) && is_array($term_id)) {

    in search.php, does that fix the problem?

    I was add next lines to code

    if (empty($term_tax_id))
    	$term_tax_id = array();
    				
    print_error_log( '$term_tax_id = ' );
    print_error_log( $term_tax_id );

    And this is a result:

    [30-Jul-2017 20:58:05 UTC] $term_tax_id =
    Array
    (
    [0] => 118
    )

    [30-Jul-2017 20:58:05 UTC] $term_tax_id =
    Array
    (
    [0] => 225
    )

    [30-Jul-2017 20:58:05 UTC] $term_tax_id = 225

    [30-Jul-2017 20:58:05 UTC] WordPress database error Unknown column ‘Array’ in ‘where clause’ for query SELECT term_taxonomy_id
    FROM wp_term_taxonomy
    WHERE term_id = Array AND taxonomy = ” made by require(‘D:\My Documents\My Web Sites\3ddkstudio.com\wp-blog-header.php’), wp, WP->main, WP->query_posts, WP_Query->query, WP_Query->get_posts, apply_filters_ref_array, WP_Hook->apply_filters, relevanssi_query, relevanssi_do_query, relevanssi_search, relevanssi_get_term_tax_id

    [30-Jul-2017 20:58:05 UTC] PHP Fatal error: Uncaught Error: [] operator not supported for strings in D:\My Documents\My Web Sites\3ddkstudio.com\wp-content\plugins\relevanssi\lib\search.php:245
    Stack trace:
    #0 D:\My Documents\My Web Sites\3ddkstudio.com\wp-content\plugins\relevanssi\lib\search.php(1291): relevanssi_search(Array)
    #1 D:\My Documents\My Web Sites\3ddkstudio.com\wp-content\plugins\relevanssi\lib\search.php(49): relevanssi_do_query(Object(WP_Query))
    #2 D:\My Documents\My Web Sites\3ddkstudio.com\wp-includes\class-wp-hook.php(300): relevanssi_query(Array)
    #3 D:\My Documents\My Web Sites\3ddkstudio.com\wp-includes\plugin.php(244): WP_Hook->apply_filters(Array, Array)
    #4 D:\My Documents\My Web Sites\3ddkstudio.com\wp-includes\class-wp-query.php(3007): apply_filters_ref_array(‘the_posts’, Array)
    #5 D:\My Documents\My Web Sites\3ddkstudio.com\wp-includes\class-wp-query.php(3248): WP_Query->get_posts()
    #6 D:\My Documents\My Web Sites\3ddkstudio.com\wp-includes\class-wp.php(617): WP_Query->query(Array)
    #7 D:\My Documents\My Web Sites\3ddkstudio.co in D:\My Documents\My Web Sites\3ddkstudio.com\wp-content\plugins\relevanssi\lib\search.php on line 245

    Plugin Author Mikko Saari

    (@msaari)

    Turns out this was a slightly larger issue of Relevanssi not being able to handle nested taxonomy queries – like the product visibility query from WooCommerce seen here – and solving it wasn’t quite as simple as it first seemed. But I think I got it now. Can you please test with this version of search.php to see if everything works as expected: https://www.dropbox.com/s/x9rn83jq8zqy99k/search.php?dl=0

    Thanks for bringing this up; since WooCommerce does this, this is something that will certainly be a wider problem.

    Excellent!
    This is is working.
    Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Receiving an error on some queries’ is closed to new replies.