SQL Error Unknown column ‘average_rating’
Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › SQL Error Unknown column ‘average_rating’
- This topic has 1 reply, 2 voices, and was last updated 2 hours, 34 minutes ago by
Ernest Marcinko.
-
AuthorPosts
-
July 23, 2026 at 3:30 pm #57727
Mohamed Salah
ParticipantHello,
I am experiencing performance issues and server timeouts on my site due to a recurring database error triggered during ASP’s taxonomy term searches.
It is incorrectly injecting
average_rating DESCinto theORDER BYclause of the taxonomy search query. Sincetzp_termsdoes not have anaverage_ratingcolumn, the SQL query fails.Here is the exact error from my
debug.log:Plaintext
WordPress database error Unknown column 'average_rating' in 'order clause' for query SELECT tzp_terms.name as `title`, tzp_terms.term_id as id, ... FROM tzp_terms LEFT JOIN tzp_term_taxonomy ON tzp_terms.term_id = tzp_term_taxonomy.term_id WHERE ... GROUP BY tzp_terms.term_id ORDER BY average_rating DESC, date DESC, tzp_terms.name ASC LIMIT 20000 made by ... WPDRMS\ASP\Search\SearchTaxonomyTerms->doSearch example php_error: [23-Jul-2026 14:15:44 UTC] WordPress database error Unknown column 'average_rating' in 'order clause' for query SELECT tzp_terms.name as `title`, tzp_terms.term_id as id, 1 as `blogid`, tzp_term_taxonomy.description as `content`, '' as `date`, '' as `author`, tzp_term_taxonomy.taxonomy as taxonomy, 'term' as `content_type`, 'terms' as `g_content_type`, ((case when (tzp_terms.name LIKE '%طقم%') then 3 else 0 end) + (case when (tzp_terms.name LIKE 'طقم مسامير قاعدة تواليت%') then 20 else 0 end) + (case when (tzp_terms.name LIKE '%طقم مسامير قاعدة تواليت%') then 10 else 0 end)) as `relevance` FROM tzp_terms LEFT JOIN tzp_term_taxonomy ON tzp_terms.term_id = tzp_term_taxonomy.term_id WHERE ( tzp_term_taxonomy.taxonomy IN ('category','product_cat','product_brand') ) AND ( (( tzp_terms.name LIKE '%طقم مسامير قاعدة تواليت%' )) OR (( tzp_terms.name LIKE '%طقم%' )) OR (( tzp_terms.name LIKE '%مسامير%' )) OR (( tzp_terms.name LIKE '%قاعدة%' )) OR (( tzp_terms.name LIKE '%تواليت%' )) OR (( tzp_terms.name LIKE '%مجموعة%' )) OR (( tzp_terms.name LIKE '%مجموعة كاملة%' )) OR (( tzp_terms.name LIKE '%طاقم%' )) OR (( tzp_terms.name LIKE '%سيت%' )) OR (( tzp_terms.name LIKE '%مسطرة%' )) OR (( tzp_terms.name LIKE '%سطح مستوي%' )) OR (( tzp_terms.name LIKE '%دعامة%' )) OR (( tzp_terms.name LIKE '%قاعدة تثبيت%' )) ) AND (tzp_term_taxonomy.count > 0) AND (1) GROUP BY tzp_terms.term_id ORDER BY average_rating DESC, date DESC, tzp_terms.name ASC LIMIT 20000 made by require('wp-blog-header.php'), wp, WP->main, WP->query_posts, WP_Query->query, WP_Query->get_posts, apply_filters_ref_array('posts_results'), WP_Hook->apply_filters, WPDRMS\ASP\Hooks\Filters\SearchOverride->override, WPDRMS\ASP\Query\SearchQuery->__construct, WPDRMS\ASP\Query\SearchQuery->get_posts, WPDRMS\ASP\Search\AbstractSearch->search, WPDRMS\ASP\Search\SearchTaxonomyTerms->doSearchMy Environment:
-
WordPress: 7.0.2
-
WooCommerce: 10.9.4
-
Ajax Search Pro: 4.29.1
My primary ordering in ASP is set to Relevance, and the secondary ordering is set to Publish Date Descending. This error only occurs when returning taxonomy terms as results.
Could you please advise if there is a specific compatibility setting in ASP to strictly prevent other plugins from altering the
SearchTaxonomyTermsqueries? Alternatively, is there a PHP snippet I can add to explicitly stripaverage_ratingfrom the term search order clause?Thank you for your support
-
This topic was modified 2 hours, 48 minutes ago by
Mohamed Salah.
July 23, 2026 at 3:53 pm #57729Ernest Marcinko
KeymasterHi,
That seems to be an injected query argument throug the asp_query args hook, as there are only 2 orderings. It is likely injected through the asp_query_args hook from what I can tell. That’s not something you can prevent, but you should be able to override through a snippet:
add_filter( 'asp_query_args', function ( $args ) { if ( isset($args['term_query']['orderby']) ) { $args['term_query']['orderby'] = ''; } return $args; }, PHP_INT_MAX, 1 );PS: We just released a code snippets plugin called SnipCraft – the free version has more features than anything on the market, feel free to try it 🙂
All the best,
Ernest -
-
AuthorPosts
- You must be logged in to reply to this topic.