Forums › Forums › Search & Filter Pro › Custom WP Query using ACF value showing all filter options
Tagged: WP_Query
- This topic has 5 replies, 2 voices, and was last updated 6 years, 1 month ago by
Trevor.
-
Trevor(Private) May 9, 2019 at 1:32 pm #210587
I changed the title for you 😉
Instead of the custom query, you may need to make the special conditions by changing OUR form query, using this filter:
https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments
Anonymous(Private) May 10, 2019 at 8:04 am #210688Thank you. So stick this in the theme functions, set to the correct form ID and add the same args per my wp_query. So I have ended up with:
function filter_function_name( $query_args, $sfid ) { //if search form ID = 225, the do something with this query if($sfid == 4672) { //modify $query_args here before returning it $query_args['numberposts'] = -1; $query_args['posts_per_page'] = 25; $query_args['post_type'] = 'product'; $query_args['post_status'] = 'publish'; $query_args['meta_key'] = 'special_offer'; $query_args['meta_value'] = true; } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
I have left the rest of the settings as per my last message (including the wp_query on the special_offers template where I am displaying the products). When I view the page the filters are not populating as expected, I should be seeing options for colour and size but I just see one colour option, which when I apply renders no results.
Am I doing something else wrong here?
Trevor(Private) May 10, 2019 at 3:48 pm #210799These:
$query_args['numberposts'] = -1; $query_args['posts_per_page'] = 25; $query_args['post_type'] = 'product'; $query_args['post_status'] = 'publish';
Should really be set in the form, not here. In the form, are you searching both Products and Variations?
Anonymous(Private) May 20, 2019 at 10:48 am #211680Sorry for the late reply. OK so I already have those query arguments in the function filter which is in functions.php. Now if I remove them from wp_query the page just has a standard WordPress loop to display content right? I have set the results method to “Custom” and defined the correct Results URL in Template Options – and yes I have the form set to display products & variations. With this setup I get no results at all. I can supply screengrabs of any sections that may help?
-
AuthorPosts