Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Results override behaviour
This topic contains 15 replies, has 2 voices, and was last updated by Ernest Marcinko 1 year, 5 months ago.
- AuthorPosts
- October 1, 2021 at 7:31 pm #34969
Hey there,
I have a question about the search override behaviour. I need my results page to include the deep search results that ajaxsearchpro provides, so I have enabled the override with get method to avoid use of cookies.
The population of results works fine but there is a small hitch as it does not seem to be compatible with woocommerce filtering. When trying to filter by latest, popularity, etc. It will always return the same order. And my filter sidebar only seems to recognize product titles, it will not work as expected when the search query is for category, taxonomy etc.
Do you have any suggestions?
October 4, 2021 at 7:08 am #34976Hi,
Well, it should deal with the default WooComerce ordering values – however some themes or plugins add some weird orderby values, which may not be evaluated properly.
If you want, you can add temporary FTP access, and I can try to debug to see what values are coming through, and maybe there is a way to add them to the order list.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
October 4, 2021 at 1:28 pm #34985You cannot access this content.October 4, 2021 at 2:01 pm #34989Thank you!
I have made an adjustment on the plugin code. The popularity and the alphabetical orderings were the ones not recognized. Now it should work all right. It is a bit hard to test because of the same product titles, but I see the right ordering in the query now.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
October 4, 2021 at 4:03 pm #34998You cannot access this content.October 4, 2021 at 4:17 pm #34999You cannot access this content.October 4, 2021 at 4:17 pm #35000You cannot access this content.October 5, 2021 at 9:53 am #35009Oh, so the “popular” is a custom made value, I see why it didn’t work now. Okay, for that, I placed this custom code to the functions.php file in the child theme directory:
add_filter('asp_query_args', 'add_custom_orderby_asp_query_args', 10, 1); function add_custom_orderby_asp_query_args($args) { if ( isset( $_GET['orderby'] ) && 'popular' === $_GET['orderby'] ) { $args['post_primary_order'] = "customfp DESC"; $args['post_primary_order_metatype'] = 'numeric'; $args['_post_primary_order_metakey'] = 'product_visit_count'; } return $args; }
It will resolve that.
Well, the filter probably takes the default WooCommerce query as the source and then takes the filtering. However the search override will trigger as well, so they simply override one another. I rather recommend using the filters from ajax search pro instead – it is very rare to get multiple filter plugins work together, generally it is not a good idea.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
October 5, 2021 at 12:31 pm #35011OK, thank you for the change and the information 🙂
To confirm, what were the plugin changes made for compatibility with A-Z, Z-A ordering? And will anything be changed after a plugin update?
Thanks
October 5, 2021 at 12:58 pm #35013I changed multiple files, so you can keep a backup copy of the whole plugin folder – however I will include these changes in the upcoming release, so you don’t have to worry about it 🙂
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
October 5, 2021 at 1:02 pm #35014Great, thanks again.
October 5, 2021 at 1:06 pm #35015You cannot access this content. Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
October 7, 2021 at 7:09 pm #35068Hi ernest – me again.
I’ve managed to create a mostly working solution to the issues above (where the results should be filterable) but could just do with your thoughts on one more thing. I appreciate this is out of bounds of plugin support, so please let me know if the fix is very complex and I won’t bother you anymore on this. But I’m hoping it’s a quick fix.
To summarize what we discussed before, I needed default woocommerce results to be displayed so they are filterable, which ajax search pro can do. I also needed the results to behave similarly to how ajax search pro produces preview results (search deeper in taxonomy, attributes). I now have a snippet that makes default woo results look deeper in taxonomy and attributes. It works exactly as I need but is missing one thing – displaying results from partial searches (like your plugin can do).
For example, I have a product tax value called ‘fashion’, it needs the full term to be typed for results to appear on archive. If I type ‘fash’, or ‘fashio’, and search, no results will appear. I’m trying to get it to work without the need for exact match.
Here’s the snippet that works with exact match only – if there is a quick fix to make it work with partial searches too, please let me know! Noone else on the internet has been able to help and I’ve tried everywhere! :
add_filter( ‘posts_search’, ‘woocommerce_search_product_tag_extended’, 999, 2 );
function woocommerce_search_product_tag_extended( $search, $query ) {
global $wpdb, $wp;$qvars = $wp->query_vars;
if ( is_admin() || empty($search) || ! ( isset($qvars[‘s’])
&& isset($qvars[‘post_type’]) && ! empty($qvars[‘s’])
&& $qvars[‘post_type’] === ‘product’ ) ) {
return $search;
}// Here set your custom taxonomies in the array
$taxonomies = array(‘product_cat’, ‘pa_region’);$tax_query = array(‘relation’ => ‘OR’); // Initializing tax query
// Loop through taxonomies to set the tax query
foreach( $taxonomies as $taxonomy ) {
$tax_query[] = array(
‘taxonomy’ => $taxonomy,
‘field’ => ‘name’,
‘terms’ => esc_attr($qvars[‘s’]),
);
}// Get the product Ids
$ids = get_posts( array(
‘posts_per_page’ => -1,
‘post_type’ => ‘product’,
‘post_status’ => ‘publish’,
‘fields’ => ‘ids’,
‘tax_query’ => $tax_query,
) );if ( sizeof( $ids ) > 0 ) {
$search = str_replace( ‘AND (((‘, “AND ((({$wpdb->posts}.ID IN (” . implode( ‘,’, $ids ) . “)) OR (“, $search);
}
return $search;
}October 8, 2021 at 6:37 am #35075Interesting. Do the partial matches work if this code is disabled?
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
October 8, 2021 at 2:16 pm #35091Yes they do. Default woo search only looks in titles, and it will still find results if I search for ‘te’ , ‘tes’, products with the name test1, test2, will appear.
But of course I need the code so the woo search can look inside taxonomies too, and it should work with partial queries.The code serves the purpose of ‘mirroring’ what your plugin is showing for results – I need it to do this so it my filtering will be fully compatible.
1. Search with ajaxsearchpro
2. preview list appears
3. user proceeds with clicking magnifier or enter key or view more button
4. user redirected to woo archive
5. Woo archive is now showing results from default woo search, in order to be compatible with filtering. Hence I’m trying to get woo search to look in tax, attr, with partial matches.My code is nearly there but just doesn’t work with partial queries.
Please say if I’m not making sense as this has become a bit of a weird setup.
Thanks again
- AuthorPosts
You must be logged in to reply to this topic.