Using distance:from and distance:to as result parameters in an embed
This is a continuation of this thread on stackexchange:
http://expressionengine.stackexchange...
I'm geocoding a UK postcode and embedding a basic results template in this block:
{exp:stash:parse process="inline" parse_depth="3"}
{exp:stash:set name="postcode" parse_tags="yes" type="snippet"}
{exp:low_search:keywords query="{segment_3}"}
{/exp:stash:set}
{exp:gmaps:geocoder address="{postcode}"}
{result}
{embed="_components/localrep" lat="{latitude}" lng="{longitude}"}
{/result}
{/exp:gmaps:geocoder}
{/exp:stash:parse}
The included file looks like this:
{exp:low_search:results
channel="local_rep"
distance:from="{embed:lat}|{embed:lng}"
distance:to="rep_lat|rep_lng"
}
{if no_results}NO RESULTS{/if}
{title} {low_search_distance}
{/exp:low_search:results}
If I output
{embed:lat}|{embed:lng}
at the top of the included template, they are fine, it's just getting them to work within the results tag (currently returns 'NO RESULTS'. It's a parse order issue for sure - is there an alternative way to get those values working within the results tag?
Replies
Low 27 Oct 2015 13:40
What are your EE and Low Search versions?
Also, can you enable the template debugger and look up all lines that mention Low Search? What does that say?
paul.bellamy 27 Oct 2015 14:51
Ok I can see this in the template debugger:
EE version is 2.10.1 and Low search is 4.0.0
Low 27 Oct 2015 14:54
Can you upgrade to the latest version (4.4.0)?
There also should be lines with something like "Low Search: some message" in there. Can you copy/paste those here, too?
paul.bellamy 27 Oct 2015 15:05
OK I've updated to 4.40. I actually think that the geocoder is giving me bogus lat/lng values. (22.4029447,91.7617178 equates to somewhere in Bangladesh)... so I need to investigate that before troubling you any further Low!
paul.bellamy 27 Oct 2015 15:38
OK so even if I hand the results tag some 'real' (tested) latlng values, I still get no results (see below) - should I be setting some kind of disatnce/radius?
Low 27 Oct 2015 15:47
Okay, can you try and
- backup your exp_channel_data table;
- make sure the Field Content property of the lat/long fields are set to Decimal.
Does that help?
paul.bellamy 27 Oct 2015 16:17
OK I did this (and re-geotagged the entries). I also created a collection (which I'd neglected to do before!) and indexed it. Still nothing. So weird. I tried changing the results param from channel= to collection= but that didn't do anything either. I also tried hard-coding the lat|lng values in the results tag, but still nothing.
It looks like the results tag is trying to process my keywords (the postcode) in combination with the latlng values:
I'm using the keyword search to convert into latlng and then embedding the search results tag. Maybe all this hacking around isn't going to work. I wish geofinder wasn't broken :)
Low 27 Oct 2015 16:22
The fact that the Distance filter fires before the Keywords, and the No Results is return after the Keywords filter does its thing, makes me believe the Distance filter actually does return entries.
You can make sure the query generated by the Distance filter is generating results by looking up the DB query in the output profiler (look for 'distance') and executing that query in, say, Sequel Pro or PhpMyAdmin.
I'd also recommend renaming the name="keywords" input field for the postcode lookup. Use name="postcode" instead. Because, as you can see, the Keywords filter is triggered if there are keywords given.
paul.bellamy 27 Oct 2015 16:31
Thanks Low. If I change keywords into postcode in the querystring, I get results (with a hard-coded lat/lng)!
How can I access the postcode value in the template if I don't use 'keywords='? Previously I was using
{exp:low_search:keywords query="{segment_3}"}
but I won't be able to use that now...Low 27 Oct 2015 16:33
If you're sending it in a Low Search form, you can get to any parameter value with {low_search_foo} in a Filters, Form or Results tag: http://gotolow.com/addons/low-search/...
paul.bellamy 27 Oct 2015 16:47
So the value of
?postcode=ab12+3cd
should be accessible via {low_search_postcode}?I've tried a simple test but the tag isn't getting parsed, it's just outputting {low_search_postcode}.
Sorry in advance if I'm being stupid.
Low 27 Oct 2015 16:50
Are you encoding queries or using GET vars?
If you were using {exp:low_search:keywords} tag before, you can also try and use
paul.bellamy 27 Oct 2015 16:54
That did it. Thank you so much for your patience in helping me with this - it's very much appreciated.