Results override behaviour

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 Ernest Marcinko 2 years, 6 months ago.

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #34969
    itsjonesyy70
    itsjonesyy70
    Participant

    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?

    #34976
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

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


    #34985
    itsjonesyy70
    itsjonesyy70
    Participant
    You cannot access this content.
    #34989
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

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


    #34998
    itsjonesyy70
    itsjonesyy70
    Participant
    You cannot access this content.
    #34999
    itsjonesyy70
    itsjonesyy70
    Participant
    You cannot access this content.
    #35000
    itsjonesyy70
    itsjonesyy70
    Participant
    You cannot access this content.
    #35009
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Oh, 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 :)


    #35011
    itsjonesyy70
    itsjonesyy70
    Participant

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

    #35013
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

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


    #35014
    itsjonesyy70
    itsjonesyy70
    Participant

    Great, thanks again.

    #35015
    Ernest Marcinko
    Ernest Marcinko
    Keymaster
    You cannot access this content. Best,
    Ernest Marcinko

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


    #35068
    itsjonesyy70
    itsjonesyy70
    Participant

    Hi 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;
    }

    #35075
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Interesting. 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 :)


    #35091
    itsjonesyy70
    itsjonesyy70
    Participant

    Yes 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

Viewing 15 posts - 1 through 15 (of 16 total)

You must be logged in to reply to this topic.