Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Using the asp_query_args filter to always include products with a specific term
This topic contains 4 replies, has 2 voices, and was last updated by paulmiller300070 3 years, 3 months ago.
- AuthorPosts
- February 9, 2020 at 3:07 am #25738
Hi there,
I would like to update the search results so they ALWAYS include WooCommerce products that match a particular taxonomy tag (ID of 59 in this case). I believe I need to use the asp_query_args filter to include a clause similar to “OR $term_id = 59”, but I’m not clear on how to do that from the documentation.
In this case, I want the results to match the keywords entered by the user AND always return products that have that term_id.
Can you point me in the right direction?
Thanks,
PaulFebruary 10, 2020 at 6:12 pm #25752Hi Paul,
I’m afraid the asp_query_args is not going to help here, as you want a union of two result sets – one matching the phrase, and another one not matching but belonging to a certain category.
Best,
For this to work properly, you would have to completely edit the core search to add a separate criteria (with a left join query) to include the required items as well.
While it sounds simple, this is actually requires a decent modification, unfortunately I cannot suggest a few lines of code to make this work.
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
February 12, 2020 at 12:36 pm #25785Hi Ernest,
Thank you for your reply. I’m quite comfortable with SQL, having started early on as a database developer and administrator.
Can you tell me which hook I should leverage or which function I should override? I can probably take it from there.
Thanks!
PaulFebruary 12, 2020 at 12:52 pm #25787Hi Paul,
Well, you can try a custom function, that lets you inject SQL queries within the main search query:
add_filter( 'asp_query_args', 'asp_custom_query_args', 10, 2 ); function asp_custom_query_args($args, $search_id) { $args['cpt_query'] = array( 'fields' => '', 'join' => '', 'where' => '', 'orderby' => '' ); return $args; }
These are replaced in wp-content/plugins/ajax-search-pro/includes/classes/search/class-asp-search-cpt.php file, namely the {args_fields}, {args_join} etc.. pseudo variables.
You might have to directly modify the query within the same file.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
February 12, 2020 at 3:53 pm #25790Great, thank you.
- AuthorPosts
You must be logged in to reply to this topic.