Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Can you please add additional query_add_select/join/where filters? › Reply To: Can you please add additional query_add_select/join/where filters?
I have found some bugs in this mechanism.
1. The attachment_query arguments don’t work with an index table search. Line 37 of ajax-search-pro\includes\classes\search\class-asp-search-attachments.php replaces the rest of the function with class-asp-search-indextable.php, which only checks for $args[‘cpt_query’]
I did the following, but perhaps you will have a better solution for the next update.
if ($words == "attachment"){
if ( isset($args['attachment_query']) && is_array($args['attachment_query']) ) {
$this->query = str_replace(
array('{args_fields}', '{args_join}', '{args_where}', '{args_orderby}'),
array($args['attachment_query']['fields'], $args['attachment_query']['join'], $args['attachment_query']['where'], $args['attachment_query']['orderby']),
$this->query
);
} else {
$this->query = str_replace(
array('{args_fields}', '{args_join}', '{args_where}', '{args_orderby}'),
'',
$this->query
);
}
if ( isset($args['attachment_query'], $args['attachment_query']['groupby']) && $args['attachment_query']['groupby'] != '' ) {
$this->query = str_replace('{args_groupby}', $args['attachment_query']['groupby'], $this->query);
} else {
$this->query = str_replace('{args_groupby}', "$wpdb->posts.ID", $this->query);
}
}
else {
if ( isset($args['cpt_query']) && is_array($args['cpt_query']) ) {
$_mod_q = $args['cpt_query'];
foreach ($_mod_q as $qk => $qv) {
$_mod_q[$qk] = str_replace($wpdb->posts . '.ID', 'asp_index.doc', $_mod_q[$qk]);
}
$this->query = str_replace(
array('{args_fields}', '{args_join}', '{args_where}', '{args_orderby}'),
array($_mod_q['fields'], $_mod_q['join'], $_mod_q['where'], $_mod_q['orderby']),
$this->query
);
}
else {
$this->query = str_replace(
array('{args_fields}', '{args_join}', '{args_where}', '{args_orderby}'),
'',
$this->query
);
}
}
2. I get the following error (excerpted) :
WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘DISTINCT asp_index.doc as id, asp_index.blogid as blogid, ‘pagepost’ a’ at line 4]
SELECT pm.meta_value as activityid, DISTINCT asp_index.doc as id, asp_index.blogid as blogid, ‘pagepost’ as
The problem being with the Improved title query str_replace – it adds DISTINCT to the query, but the {args_fields} and $add_select hooks are inserted before that.
I fixed it by moving these to the bottom of the SELECT section, before FROM, but I don’t know if this is the appropriate place to do it. I had to move the comma in the snippet you provided above to be at the front rather than trailing.