0

I'm coming from EE 1.6 and currently migrating to EE5. I have noticed issues when using the Simple Search Form and relationship fields.

My tag:

{exp:search:simple_form 
    channel="books|authors"
    show_future_entries="yes"
    result_page="result" 
    where="all" 
    search_in="everywhere"
}

My channel relationship:

Parent Channel: Books

Child Channel: Authors

Include in search setting is enabled for the relationship field.

Example search text: David.

Search result only shows entries from Authors channel.

I'm expecting the result to also show entries from Books channel which has David as the author. (not to be confused with EE channel author).

Is this is a bug / not supported feature?

0

The simple search tag as its name suggests provides a simple search service. With the settings in your code snippet it should return details of channel entries in the "Books" and "Authors" channels that contain the word "David".

It looks from your question that what you actually want is to be able to list out the Books that include an author with "David" in their name - even if the Book entry itself does not.

One way to do this is to use each result returned by search that is from the Authors channel to generate a list of the books that Author has a relationship with in the Books channel (i.e. list out the Author entry's Parents). The way to do this is well described in the EE documentation - and if you do this you might end up with code a bit like this:

{exp:search:simple_form 
    channel="books|authors" 
    show_future_entries="yes" 
    result_page="result" 
    where="all" 
    search_in="everywhere"
}

{if channel_short_name == "authors"} {!-- We've got an Author result --}

<h3><bold>Author: </bold>{title}</h3>
<p>Books:</p>
<ul>
{parents field="relationship_field"} {!-- You should replace this with the name of your relationship field --}
    <li>
{parents:title} - {parents:field1} - {parents:field2}
    </li>
{/parents}
</ul>

{if:else}  {!-- We've got an Book result --}

<h3><bold>Book: </bold>{title}</h3>
<p>Authors:</p>
<ul>
{relationship_field} {!-- You should replace this with the name of your relationship field --}
    <li>
{relationship_field:title} - {relationship_field:field1} - {relationship_field:field2}
    </li>
{/relationship_field}
</ul>

{/if}
{/exp:search:simple_form}

Hope this helps.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.