I’ve run into an issue where I need to conditionally show content if an EE relationship field is empty. However the {if relationship-field} conditional is not working. Nor is any variation of that such as {if relationship-field == ""} or {if "{relationship-field}" == ""} or {if "{relationship-field}" != ""}. No dice on any of these.


The solution turns out to be fairly simple and the logic can pretty much work the same. EE relationship fields let you pull the count separately from the tag pair like this:


So, the solution is to use that in our conditional logic:

{if "{relationship-field:count}" == ""}
    do stuff
    do relationship stuff
  • Shouldn't it be ... == 0 instead of == "" ?
    – BNetz
    Mar 26 '16 at 0:06
  • This doesn't work in EE 3.5.11. what version does this apply to?
    – Andy
    Oct 3 '17 at 11:25

Long time to add to this but...

  do relationship stuff
  {if relationship-field:no_results}
    Empty stuuf
  • Thanks for this. I think this is the most up-to-date solution following changes to EE's conditionals. TJ Draper's code didn't work for me. Your no_results code worked like a charm. Jun 19 '15 at 13:53
  • Thank you for your answer, Nevsie-Modeten. Your no_results code example really helped me fix my problem.
    – user7225
    Mar 24 '16 at 18:14
  • I love you all... Just what I needed. Thanks.
    – samc449
    Mar 31 '16 at 9:16

I would like to add the following also works:

{if "{relationship_field:count}" == 1}
Do relationship stuff

In my case, I only want to display formatted content if there is relationship data:

{if "{bk_author:count}"=="1"}
<h5 class="small">by {bk_author backspace="2"}<a href="/author/{bk_author:url_title}">{bk_author:title}</a>, {/bk_author}

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.