Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Search result page problem
- This topic has 3 replies, 2 voices, and was last updated 1 year, 6 months ago by
Ernest Marcinko.
-
AuthorPosts
-
November 20, 2024 at 7:39 am #51914
dermonotone
ParticipantHi there,
i have problems with my search result page.
In Ajax search pro the sroting of products is okay it does sort the products _price ASC.But on the search result page the products are not sorted by _price. it is random.
Any help how i can archive the sorting on search page too? (should also be _price ASC).
i treid this code but then it does not respect the search terms and i get more products then searched (eg when i search blue shirt it shows all prodiucts with blue OR shirt. it should be blue AND shirt)function custom_woocommerce_get_catalog_ordering_args( $args ) { if ( is_search() ) { $args['orderby'] = 'meta_value_num'; $args['order'] = 'ASC'; $args['meta_key'] = '_price'; } return $args; } add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' ); function custom_search_order_by_price( $clauses, $query ) { global $wpdb; if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) { if ( strpos( $clauses['join'], 'pm.meta_key = \'_price\'' ) === false ) { $clauses['join'] .= " LEFT JOIN {$wpdb->postmeta} AS pm ON {$wpdb->posts}.ID = pm.post_id "; } $clauses['where'] .= " AND pm.meta_key = '_price' "; $clauses['orderby'] = " CAST(pm.meta_value AS DECIMAL) ASC "; } return $clauses; } add_filter( 'posts_clauses', 'custom_search_order_by_price', 10, 2 );thanks for oyur help
November 20, 2024 at 8:57 am #51921Ernest Marcinko
KeymasterHi,
The sorting should be the same if the search override is active.
I tried a few queries but the ordering seems to be all right on my end: https://i.imgur.com/esKZtzl.png
Everything seems to be in the same order. Did you manage to resolve it, or do you get different results?November 20, 2024 at 10:08 am #51922dermonotone
ParticipantHi,
yes i was able to fix it. in search override i had to switch from post to get…sorry and thanks gain!
November 20, 2024 at 10:14 am #51923Ernest Marcinko
KeymasterYou cannot access this content.
-
AuthorPosts
- You must be logged in to reply to this topic.