Forums › Forums › Search & Filter Pro › Price filter not updating after (custom) search
- This topic has 8 replies, 2 voices, and was last updated 7 years, 5 months ago by
Trevor.
-
Anonymous(Private) November 7, 2018 at 8:16 am #192976
Hi,
We have a filter for a WooCommerce shop. After we search in the search field, the price is not updated in the filter. and set to e.g. €4-€4 (which is the lowest price of a product in the shop.)
This is the code we used to extend the search functionality so we can search for the slug (which is also the SKU):
/** * Extend search. * * @param array $query WP_Query object. * @return void */ function search_filter( $query ) { if ( ! is_admin() && null !== $_GET['_sf_s'] ) { $search = $_GET['_sf_s']; $query->set( 'pr_title', $search ); // LIKE post_name via Filter. } } add_action( 'pre_get_posts', 'search_filter', 10 ); /** * Filter pr_title query var. * * @param string $where Where string. * @param array $wp_query WP_Query object. * @return string */ function flux_posts_where( $where, $wp_query ) { global $wpdb; $pr_name = $wp_query->get( 'pr_title' ); if ( null !== $pr_name ) { $where .= ' AND ' . $wpdb->posts . '.post_name LIKE \'%' . $wpdb->esc_like( $pr_name ) . '%\''; } return $where; } add_filter( 'posts_where', 'flux_posts_where', 10, 2 );Is there something we are doing wrong?
Because our shop is a wholesale shop, I will send you the URL and login in a private reply.
Thank you,
RubenTrevor(Private) November 7, 2018 at 8:57 am #192983I am not sure if this relates directly to your question, but maybe it does. The Price field is a slider, and the slider, if set to auto detect, does not ‘react’ to changes made in other fields in the form. This is intentional, as to do so could have undesirable consequences. Read more about this here:
https://support.searchandfilter.com/forums/topic/custom-max-price-for-price-slider/#post-77119
If that is not the issue, please get back to me.
Anonymous(Private) November 7, 2018 at 12:46 pm #193004Hi Trevor,
After inputting a search term, the slider is set to min-min (€4-€4) instead of min-max (€4-€194) without us manually updating it.
The price not updating is not really an issue for us, we just find it strange that it is ‘automatically’ updated to a wrong value.
Also, even after hitting the reset button, the price is not set to its initial value (€4-€194).
Anonymous(Private) November 8, 2018 at 7:54 am #193089We would like to let the user search on SKU.
Because our shop has 1000 variable products (with 20k+ variations), we prevent the search-query to be super heavy: we have set our product-slug as the SKU: https://arwb2b.be/123456 (where 123456 is equal to the SKU), we are extending the search query to search on the post_name (slug) in the posts-table of our database.
This is working fine.However, the main problem is that the range-slider for the price is not staying in its initial ‘position’ and is set to €4-€4 after we hit the search query.
We also need to click twice on the reset button before the slider is reset to €4-€194.Are we forgetting to pass some value to our extended search query?
Trevor(Private) November 8, 2018 at 11:14 am #193127I notice that all the other fields are empty. I wonder whether you need to sdo the search as a Custom type instead of WooCommerce, and then use our pre_get_posts method to attach our query to the page? Like this:
function pre_get_posts_function($query) { //this would be a pre_get_posts you already have in place somewhere //then set <code>search_filter_id</code> $query->set("search_filter_id", 123); } add_action( 'pre_get_posts', array($this, 'pre_get_posts_function') );OR, to use your code to fetch an array of Post IDs and use post__in in the query by modifying the query arguments:
https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments
-
AuthorPosts