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

Support archive

Search Relationships sample code explanation please

john 26 Nov 2013 15:26 question, complete

Could you please explain this / comment each bit of this (i assume this is relationship field example code) form tag sample code snippet please?

http://pastie.org/8510095

For me, i have a set of products which have a few fields that are relationships.

What i want is a select field of all the entries titles in that related channel . Then i want the user to be able to choose one entry and it bring back results of all the products that have that entry as a relationship.

So i guess i also want to return results from only one channel too / search in only one channel.

Anyway, any clarity on how that code sample works would be lovely. Thanks!

Replies

  1. Low 26 Nov 2013 16:04

    First off, here's how parameters work in Low Search.

    Secondly, here's how the Relationships filter works.

    Combining this, if you need to filter results by the child entry that they might have, you'll need something like this in your Form tag:

    <select name="child:rel_field_name"> 
    {exp:channel:entries channel="child_channel_name" ... }
    <option value="{entry_id}">{title}</option>
    {/exp:channel:entries}
    </select>


    rel_field_name is the relationship field name containing the child entries. child_channel_name is the channel that contains all child entries.

    Hope that makes sense.

  2. john 26 Nov 2013 16:16

    Well, ok, i sort of see, but i just want the title matched i guess. I don't specifically want to search a field in the related entry.

    I already tried the code you pasted here, but it rendered nothing in the select. I guess i'm doing something very wrong.

  3. john 26 Nov 2013 16:21

    You can close this off now. I'll try a different solution.

  4. Low 26 Nov 2013 16:22

    You're not searching a field in the related entry with that code. You're limiting the results to entries that have the selected entry as a child. That's what you want, right?

    a select field of all the entries titles in that related channel

    Create a select-element with name="child:rel_field_name", and use the channel:entries tag to create a list of options. Remember dynamic="no" and all that stuff.

    choose one entry and it bring back results of all the products that have that entry as a relationship

    So a single select then. Choose one, so the {entry_id} of that entry is selected and submitted in the form. The results will then be filtered by entries having that entry as a child.

  5. Low 26 Nov 2013 16:23

    Here to help if you want it, John.