Forums Forums Search & Filter Pro Custom WP Query using ACF value showing all filter options

Tagged: 

Viewing 5 posts - 1 through 5 (of 5 total)
  • Trevor
    #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
    #210688

    Thank 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
    #210799

    These:

            $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
    #211680

    Sorry 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?

    Trevor
    #211725
    This reply has been marked as private.
Viewing 5 posts - 1 through 5 (of 5 total)