Using the asp_query_args filter to always include products with a specific term

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 paulmiller300070 3 years, 3 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #25738
    paulmiller300070
    paulmiller300070
    Participant

    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,
    Paul

    #25752
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi 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.
    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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #25785
    paulmiller300070
    paulmiller300070
    Participant

    Hi 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!
    Paul

    #25787
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi 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 :)


    #25790
    paulmiller300070
    paulmiller300070
    Participant

    Great, thank you.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.