ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Displaying relationship field in search

January 15, 2010 12:27am

Subscribe [3]
  • #1 / Jan 15, 2010 12:27am

    honey4d

    15 posts

    Hi.

    I have two weblogs ‘Region’ & ‘Constituency’. Constituency contains a custom field called ‘region-link’ (searchable relationship field) that I have used to link each constituency with a region.

    I have added a search to my site so that users can search by constituency to find their region.

    How I would like the results to appear…

    Searching for: ‘Poole’ found 1 results.

    Poole can be found in the region of Dorset (link on ‘Dorset’)


    ...I appear to be unable to display the Region (Dorset in the eg above) using the following code. I just get a number appear but can’t see what it’s related to.

    <h2>Search results:</h2>
    <p>Searching for: <b>{exp:search:keywords}</b> found {exp:search:total_results} results.</p>
    
    <p>{exp:search:search_results id="region"}</p>
    
    <p>{title} can be found in region: <a href="http://{auto_path}">{region-link}</a><br />
    {/exp:search:search_results}</p>
    
    <p>{embed="includes/footer"}


    This is my search code:

    {exp:search:simple_form weblog="region|constituency" status="open" result_page="/search-results" search_in="everywhere"}
    <label for="keywords">Search</label>
    <input type="text" name="keywords" id="keywords" size="20" maxlength="50" />
    <input id="search-button" name="submit" value="submit" alt="search" type="image" src="/images/search-btn.png" /></p>
    {/exp:search:simple_form}


    Can anyone help please?

    Thanks

  • #2 / Jan 16, 2010 3:26pm

    Greg Salt

    3988 posts

    Hi honey4d,

    The number that is returned is the relationship ID. This value is what is passed into the {related_entries} tag pair using the id parameter in the weblog entries tag but this is not available in the search results tag.

    Cheers

    Greg

  • #3 / Jan 18, 2010 1:16pm

    honey4d

    15 posts

    Thanks Greg

    Is there a way that I can make the region appear in the results? Or, could I somehow add a hack to the auto_path to link it to the region in which the constituency belongs?

    i.e….

    mywebsite.org.uk/poole (constituency page which does not contain any content)

    redirects to..

    mywebsite.org.uk/dorset


    Thanks
    Jon

  • #4 / Jan 18, 2010 7:37pm

    Adam Dorsey

    1439 posts

    I was able to get this working by using the related_entries pair:

    {exp:search:search_results}
    
    {title} can be found in region: 
    
    {related_entries id="region"}
    <a href="http://{auto_path}">{region-link}</a><br>
    {/related_entries}
    
    {/exp:search:search_results}

    Does this help?

  • #5 / Jan 18, 2010 8:47pm

    honey4d

    15 posts

    Thank you. I changed the id to the relationship field and displayed the {title} and it works.

    {exp:search:search_results}
    {title} can be found in region:
    {related_entries id="region-link"}
    <a href="http://{auto_path}">{title}</a><br>
    {/related_entries}
    {/exp:search:search_results}

    The auto_path link is broken but I think I can fix that.

    Thanks again. Jon

  • #6 / Jan 18, 2010 8:51pm

    Adam Dorsey

    1439 posts

    No problem, if you still have issues, please feel free to post again 😊

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases