The forums are closed and will be removed when we launch our new site.
Looking for support? You can access the support system via your account.
Pekka Gaiser
Forum Replies Created
-
Pekka Gaiser in reply to:
Injecting custom dropdowns to the filter bar(Private) August 8, 2018 at 9:03 am #184827To be clear for future readers, I’m doing the above before the page is getting rendered, in my case in the theme’s
functions.php
.Pekka Gaiser in reply to:
Injecting custom dropdowns to the filter bar(Private) August 8, 2018 at 9:02 am #184825Fair enough!
Should anyone else have the same problem: I’ve managed to find a hacky but reasonable solution for now: when parsing the drop-down contents (like turning “last_quarter” into a start and an end date) I inject some JavaScript into the document that sets the dropdown to the right value.
if (isset($_GET["_sfm_pseudofield_daterange"])) { $daterange = $_GET["_sfm_pseudofield_daterange"]; .... Handle the date stuff // Now remove the GET parameter so it doesn't get used as a filter and lead to 0 results unset($_GET["_sfm_pseudofield_daterange"]); // Use JavaScript to correctly set the dropdown again even though GET parameter was unset add_action( 'wp_head', function() use($daterange) { ?><script>jQuery(document).ready(function(){ jQuery("[name='_sfm_pseudofield_daterange[]']").val("<?= htmlentities($daterange);?>");});</script><? } ); }
As a feature request, it would be awesome to have a new “empty” field type (Text field, dropdown, check box, etc.) that gets passed along with the rest of the form, plus a documented interface for altering query parameters in the
sf_edit_query_args
hook.Pekka Gaiser in reply to:
Injecting custom dropdowns to the filter bar(Private) August 7, 2018 at 2:53 pm #184766OK! The custom filter route didn’t work out – looking at the plugin source code I don’t think anything is ever actually done with
search_filter_override
. I tried looking atglobal $searchandfilter
but that doesn’t seem really open to outside manipulation. But, I can intercept the $_GET parameters directly and do my changes there. It’s hacky, but it does the job.Sadly I still can’t do what I need to do, though, because the workflow I’m creating has the search bar as a permanent feature on the page and the period selector will always snap back to the default value while everything else stays in place. That’s not acceptable from a UX perspective. Say for example, I have a form with
– A dropdown linked to an unused “period” meta field, with the values ‘last_month’, ‘last_quarter’
– Adate_from
anddate_to
fieldNow after submitting the form, I can fiddle with
$_GET
, parse theperiod
parameter and setdate_from
anddate_to
accordingly. But I have to remove$_GET["sfm_period"]
because otherwise that gets used as a filter, which would of course yield 0 results! I can remove the field but then S&F will think the value is not set, and the “period” dropdown will snap back to its default value.What this would require is the ability to have dropdowns that aren’t actually linked to a real meta field and so what you select there doesn’t play into the query.
Any ideas around this would be welcome.
Pekka Gaiser in reply to:
Injecting custom dropdowns to the filter bar(Private) August 3, 2018 at 10:15 am #184526That sounds perfect! However, using that filter, I can’t seem to reach the relevant part of the query. I created a dropdown with manual values (“thisquarter”, “lastquarter”) and am seeing the selected value being passed to the search page:
(my url)?_sfm_period=thisquarter
However, when I try to get hold of
_sfm_period
using the filter you mentioned, it isn’t there! What I see isArray
(
[paged] => 1
[search_filter_id] => 3136
[search_filter_override] =>
[posts_per_page] => 500
[meta_query] => Array
(
)[post_type] => shops
Which appear to be the static parts of the form but not the properly spelled out query (yet).
Should I just add my correct date values to the
meta_query
array?Pekka Gaiser in reply to:
Injecting custom dropdowns to the filter bar(Private) August 2, 2018 at 11:18 am #184413The Meta field control indeed works for options two and three. Thank you!
Yes, a “date range” feature would be really cool, but perhaps a bit esoteric and personally I’d already be happy with an easy way to fiddle with the query before it is run. So that I could set up a dropdown with “current quarter” / “last quarter” / etc. as selectable values and then intercept them & turn them into dates that S&F can understand before running the custom WP_query invoking the filter.
-
AuthorPosts