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.

Filter Parent Entries by Field Value?

October 23, 2013 11:32am

Subscribe [2]
  • #1 / Oct 23, 2013 11:32am

    yaweb

    4 posts

    I am using the EE relationships field type to create a relation between two channels.  This is a one to many relationship specified by the child entry.  When displaying the parents on the child layout, I need to have the ability to filter results returned by the parents tag by a parent field value. 

    I tried using the syntax below, but it does not work.

    {parents field="related_entry" search:custom_field="custom_value"}
        {title}
    {/parents}

    Is something like this possible using EE relationships?  I am open to using other relationship fieldtypes if they support this functionality.

  • #2 / Oct 23, 2013 2:42pm

    Rob Allen

    3107 posts

    You may be able to filter using a conditional instead…

    {parents field="related_entry"}
    {if parents:custom_field == "custom value"}
        {title}
    {/if}
    {/parents}
  • #3 / Oct 23, 2013 2:45pm

    yaweb

    4 posts

    I did try this approach, but it was going to be a pain to implement because I would have no way to tell if there were no results for my conditions. 

    If there aren’t any better alternatives, I may have to do it this way, but I won’t be able to display a message for no results. 

    I was just hoping that there was a better way.

  • #4 / Oct 23, 2013 5:25pm

    Rob Allen

    3107 posts

    This may work…

    {parents field="related_entry"}
    {if parents:custom_field == "custom value"}
        {title}
    
        {if:parents:no_results}
        Nothing found
        {/if}
    
    {/if}
    {/parents}

    Or this…

    {parents field="related_entry"}
    {if parents:custom_field == "custom value"}
        {title}
    
        {if:else}
        Nothing found
        {/if}
    
    {/if}
    {/parents}

     

  • #5 / Oct 23, 2013 5:39pm

    yaweb

    4 posts

    I will try your first suggestion.  I know for a fact that the second suggestion won’t work because it would print the no results text for every parent entry that didn’t match the field value.

  • #6 / Oct 23, 2013 6:04pm

    yaweb

    4 posts

    Second suggestion did not work either because parents:no_results applies to the entire set of parents, not to the subset of parents that match the conditional.

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

ExpressionEngine News!

#eecms, #events, #releases