Forums Forums Search & Filter Pro Filter without a (visible) form

Viewing 10 posts - 1 through 10 (of 74 total)
  • Trevor
    #270595

    You can make a form with no Form UI elements, and then use conditions set in the Posts, Tags, Categories & Taxonomies and Post meta settings tab to pre-filter/sort the page.

    I am not sure you then need the form on the page as well, but if you do, you can hide it using CSS.

    If you need more sophisticated pre-filtering, you have have to do it instead using this filter;

    https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments

    Anonymous
    #270596

    Thanks Trevor,

    I hadn’t thought of using a blank form. I’ll try that first as a proof of concept. I have over 150 landing pages though, so I’d rather avoid having to create that many forms 😛

    I took a look at that URL, but I wasn’t sure where to put it in the overall scheme of the page? If you could please help me clarify…

    I assume that in this line: $query_args['somearg'] = 'newvalue';

    I should be replacing “somearg” with the fieldname and “newvalue” with the value I want to filter on in said fieldname?

    Similarly, if I want to filter on two variables, I can just repeat that line, making changes as applicable?

    I’m using php snippets at the moment to insert code. Where should this function go in relation to the search results post grid? Right now I don’t think the new arguments are being picked up as a var_dump on $query_args returns NULL.

    Trevor
    #270598

    The filter would be used in the child theme functions.php file. I think you would have to make that many forms. Far from ideal.

    Anonymous
    #270599

    I’m hoping that, with the right methodology, simply applying the filter on each page should suffice.

    Given that each page slug contains the keywords I need to amend the query, the theory is that I can extract them from the slug and use them to populate the “somearg” and “value” fields appropriately and pass those to the search results.

    Or am I completely misunderstanding how it works?

    Trevor
    #270601

    You could pass them, yes, I guess. The problem is that most of our form types require a results page URL. But, there are ways of dynamically setting that, provided one is set by default in the form. But, it would all need to be done in PHP.

    This is not something I have tried to do, and would not want to either, as it would be highly complex.

    Anonymous
    #270602

    I’m figuring php is the way forward here.

    I’d forgotten about the results page url bit.

    Could you point me in the direction of how I might set it dynamically per page?

    Trevor
    #270604

    The notes on dynamic url setting are here:

    https://searchandfilter.com/documentation/action-filter-reference/#modify-urls

    You would need to somehow use PHP to fetch the URL and the variables.

    For both filters, there are a lot of snippets also in the forum topics.

    Anonymous
    #270640
    This reply has been marked as private.
    Trevor
    #270714

    The sfid is passed by our form to that function, and will be the Post ID of the form. In this case, is that 27601.

    How can you know? When editing the form, the ID appears in the shortcode for the form in the meta box on the right, or indeed in the browser URL. If on the main Search & Filter page in admin, the shortcodes are also shown there.

    Anonymous
    #270801

    Hi Trevor,

    I know how to find the ID. That’s why that ID is in the code :P.

    The problem, as described, is that nothing is happening.

    The resultset is exactly the same as before, when it should be different.

    If I do a var_dump() of $query_args; I get NULL, which I take to mean the if() statement is not being triggered.

    The WPBakery post grid is set to connect to S&F, and I have chosen the form in the dropdown which matches to that form ID.

    I assume the function is correct as the only thing I’ve changed is the $sfid and the respective values in $query_args['orientation'] = 'straight';

    Why might the if() statement not be picking up the $sfid?

Viewing 10 posts - 1 through 10 (of 74 total)