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.

Related Entries tag shows entries even when they have a Closed status

December 18, 2008 10:42am

Subscribe [2]
  • #1 / Dec 18, 2008 10:42am

    berkeley

    32 posts

    This question may be related to a resolved thread.

    I’d like my related entries to only show entries which have a status=“Open”. This Bug Report talks about using a conditional as a workaround, but please can someone explain what code I need to use. Many thanks

  • #2 / Dec 18, 2008 11:31am

    Mark Bowen

    12637 posts

    Hi berkeley,

    Pretty sure something like this should do it for you :

    {related_entries id="my-related-field"}
    
    {if status == "closed"}
    THIS ENTRY SHOULD NOT SHOW!!
    {if:else}
    <h2>{title}</h2>
    <p>{/if}</p>
    
    <p>{/related_entries}

    Perhaps better code to use though would be this :

    {related_entries id="my-related-field"}
    
    {if status != "closed"}
    <h2>{title}</h2>
    <p>{/if}</p>
    
    <p>{/related_entries}

    That should just show all entries that don’t have their status set to closed.

    Hope that helps.

    Best wishes,

    Mark

  • #3 / Dec 18, 2008 11:34am

    Mark Bowen

    12637 posts

    Also be very weary that even though in the control panel the Open and Closed statuses show with a capital first letter they are actually stored in the database with a small first letter so you will need to use those in the conditional as I showed above.

  • #4 / Dec 18, 2008 12:08pm

    berkeley

    32 posts

    Marvellous! Cheers Mark that did the trick - I knew the answer was fairly straightforward just wasn’t sure whereabout the if bit should go. And thanks too for the tip-off about the use of capital letters - I was using status=“Open” on my search form and it seemed to work, but I’ll amend to a small ‘o’
    Thanks again
    Ant

  • #5 / Dec 18, 2008 12:13pm

    Mark Bowen

    12637 posts

    Hi Ant,

    No problem at all. Glad that’s all working for you now.

    Actually regarding the Open / open Closed / closed part I myself would like to hear from a moderator as to whether this is important or not as I know that in some cases it could be but perhaps others it isn’t? Seems like that really should be cleared up somewhere.

    Best wishes,

    Mark

  • #6 / Dec 18, 2008 2:32pm

    Pascal Kriete

    2589 posts

    First off, thanks for helping out, Mark.

    You’re best off using lowercase.  The database stores them in lowercase and PHP comparisons are case sensitive (advanced conditionals).  In the cases where it’s used in a query it depends on the database table collation.  For a query on a case insensitive table (utf8_general_ci, for example) it won’t make a difference.  Hope that makes a bit of sense.

    berkeley, please don’t hesitate to post again as needed.

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

ExpressionEngine News!

#eecms, #events, #releases