Forums › Forums › Search & Filter Pro › Filter without a (visible) form
- This topic has 74 replies, 3 voices, and was last updated 3 years, 10 months ago by Ross.
-
Anonymous(Private) December 21, 2020 at 4:50 pm #270592
Hi,
I’ve used a form to be allow users to quickly filter out items from 300+ ish results on a search page.
The fun thing is, it’s actually a lot quicker than the WPBakery filter I have doing the same on some of my landing pages – I’m actually having problems with their performance because of the number of queries they’re performing.
The search page I have set up uses the WPBakery/S&F tie-in to pull results into a post grid and it works perfectly.
What I want to do is use the S&F query method on those landing pages, hardcoding the category filters/taxonomies depending on the landing page, and putting the results in the post grid.
I have a suspicion I need to do something using edit_query_arguments(), but I’m not quite sure how to go about it or where to put it on the individual landing pages.
Could you please advise?
Trevor(Private) December 21, 2020 at 5:03 pm #270595You 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(Private) December 21, 2020 at 5:15 pm #270596Thanks 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.
Anonymous(Private) December 21, 2020 at 5:31 pm #270599I’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(Private) December 21, 2020 at 5:56 pm #270601You 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.
Trevor(Private) December 21, 2020 at 6:23 pm #270604The 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.
Trevor(Private) December 22, 2020 at 1:44 pm #270714The 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.
-
AuthorPosts