All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

Low Search using playa relationships

Sean 9 Feb 2016 21:53 question, complete

Low,

I'm stuck on how best to proceed with what I need to do.

I have a channel TRIPS where I need to set up various filters/search links based on playa relationships within the channel entries. So I'd have search links that visitors could click for each of the following where each river/activity is a channel entry in their own channel.

River
- river one
- river two
- river three
Activity
- activity one
- activity two
-- activity three

What I've done so far is set up a "Trips" collection and now I need to be able to filter all trips so that only those with a related river one or related activity two will show on the results page.

How do I proceed with this? I've looked at the docs but am not sure exactly what to do.

Replies

  1. Low 9 Feb 2016 22:10

    As you might expect, you will need the Relationships filter. Exactly how you use it, depends on your setup.

    You want to display Trips as search results. If in the Trips channel you select a River, then the River entry is the child of the Trips entry, so you want to display Trips that have the selected River entry as a child: child:playa_field="x" (where x is the River entry ID).

    The other way round, if in the River channel you select a Trip, then the River entry is the parent of the Trips entry, so you want to display Trips that have the selecte River as a parent: parent:playa_field="x"

    I'm guessing the former is the case here, so the first example applies, where the Shops == Trips and Pizzas == Rivers (or Activities).

  2. Sean 10 Feb 2016 14:25

    Low,

    That makes sense - is it possible to do all that with the url tag as I've got an unordered list of links rather than a form?

  3. Low 10 Feb 2016 14:54

    Yeah, definitely possible. Just set the parameter on the URL tag to generate a link to that query.

  4. Sean 12 Feb 2016 15:58

    Low,

    I've made progress with this but the search results are outputting all entries in all channels.

    The links to filter are generated by the following code

     

    <ul>
    {exp:channel:entries channel="activity_type" dynamic="no" disable="pagination|comments|categories|member_data"}
    <li>
    <a href='{exp:low_search:url result_page="/finder/filter/" child:playa_field="trip_activity_type" encode="no"}'>{title}</a>
    </li>
    {/exp:channel:entries}
    </ul>



    On the search result page I'm embedding a google map using Gmaps with this embed code
     

    {embed="finder/_gmap"
    default-locations='{exp:low_variables:pair var="lv-finder-default-pins" backspace="1"}{lv-finder-default-pins:location}|{/exp:low_variables:pair}'
    default-zoom="{lv-finder-zoom}"
    }



    The embedded template is here:
    Where the {title} tag outputs every single title in all channels when it should only output the 2 or 3 that have set a relationship to hat activity type in the first code block.
     

    {if segment_2 !="filter"}

    {!--{exp:gmaps:init}--}
    {exp:gmaps:geocoding
    address="{embed:default-locations}"
    width="100%"
    height="750px"
    map_type="terrain"
    zoom_control_position="LEFT_BOTTOM"
    zoom="{embed:default-zoom}"
    }
    {/if}

    {if segment_2 =="filter"}
    {!--Low Search Stuff Here--}
    {exp:low_search:results query="{segment_3}" limit="200" dynamic="no" disable="member_data|comments|pagination"}

    {if low_search_no_results}
    <div style="width:100%;height:500px;padding:150px 40px 40px 40px;background:pink;">
    <h4 class="text-center">no search results</h4>
    </div>
    {/if}

    {!--
    // testing purposes only delete later
    // should only display titles for filtered results
    // but currently ouputs all channels/entries
    --}
    <div style="width:100%;min-height:20px;padding:2px;background-color:rgba(250, 250, 131, 0.4);">
    <p class="text-center" style="margin:3px 0 0;">-- title: {title} --</p>
    </div>

    {exp:stash:set parse_tags="yes"}
    {!--
    // stash markers to use in google map
    --}

    {if "{trip_map:marker:latlng}" !=""}
    {trip_map:marker:latlng}|
    {if:else}
    {map_points_original_site}
    {map_points_original_site:point_location_latlng}{map_points_original_site:point_location}|
    {/map_points_original_site}
    {/if}
    {/exp:stash:set}

    {/exp:low_search:results}

    {exp:gmaps:geocoding width="100%" marker="yes" width="100%" height="750px" map_type="terrain" zoom_control_position="LEFT_BOTTOM" zoom="9"}
    {address}
    {!--
    // hardcoding Glenwood springs because we're not getting any real results to fill the stash tag
    // and if nothing here the map won't load.
    // remove once working
    --}
    Glenwood Springs|{exp:stash:get name="address"}
    }
    {/address}
    {/exp:gmaps:geocoding}

    {/if}

  5. Low 13 Feb 2016 09:39

    You've got child:playa_field="trip_activity_type"

    The Relationships filter doesn't work that way. Read this bit again: http://gotolow.com/addons/low-search/...

    Following those rules, the parameter should probably look like this: child:trip_activity_type="1", where 1 is an entry ID. That means you can use {entry_id}, as you're using it inside a channel:entries tag.

    Use toggle:child:trip_ativity_type="{entry_id}" if you want to be able to have multiple selections, see http://gotolow.com/addons/low-search/...

  6. Sean 16 Feb 2016 15:05

    Low thank you for clarifying. using toggle is exactly what I needed and I am embarrassed that I didn't replay playa_field with the field name...