• Resolved s1s2

    (@s1s2)


    I have a custom post-type “containers”. Each container has an ACF relationship field called “acf_items” that can link to “item A” and/or “item B”.

    Inside a specific container page, I want to display what item is contained in it (let’s say “item A”) but I also want to say what other items are available and not on display (in this case, “item B”).

    Accordingly, I tried the following:

    [loop type=containers]
     [if field=title value='Container of Choice']
      [related acf_items]
        [-if field=title value='Item A']  
         This container only includes [field title].
        [/-if]
        [-if field=title not value='Item A']  
         Other items not in this container are: [field title].
        [/-if]
      [/related]
     [/if]
    [/loop]

    The code produces no result, as if the related items are not being evaluated one by one against value.

    I also tried to work around it by using vars:

    [loop type=containers]
     [if field=title value='Container of Choice']
      [related acf_items]
      [set item][field title][/set]
      [pass vars]
       [-if var=item value='Item A']  
         This container only includes {-ITEM}.
       [/-if]
       [-if var=item not value='Item A']  
         Other items not in this container are: {-ITEM}.
        [/-if]
       [/pass]
      [/related]
     [/if]
    [/loop]

    This, too, produces the same effect: nothing gets displayed. Yet, the [related] routine correctly outputs two separate values: “item A” and “item B”.

    It’s the [if] that doesn’t seem to do either comparison.

    Thanks for your help

Viewing 9 replies - 1 through 9 (of 9 total)
  • Is ITEM another content type?

    And you can try:

    [loop type=containers]
     [if field=title value='Container of Choice']
      [related acf_items]
        [set item][field title][/set]
      [/related]
      [pass vars]
       [-if var=item value='Item A']  
         This container only includes {-ITEM}.
       [/-if]
       [-if var=item not value='Item A']  
         Other items not in this container are: {-ITEM}.
        [/-if]
       [/pass]
     [/if]
    [/loop]
    • This reply was modified 2 years, 10 months ago by polarracing.
    • This reply was modified 2 years, 10 months ago by polarracing.
    Thread Starter s1s2

    (@s1s2)

    Yes, ITEM is another content type.

    I tried the approach you suggests and it works, but only for the first item stored in acf_items.

    Let’s say that acf_items links to item_A and item_B.

    If I close [related] before the [if] conditions as you suggest, the only item that will be evaluated will be item_A.

    Related is a multi value field?

    Thread Starter s1s2

    (@s1s2)

    Yes again.

    Here is an error anyway: You pass only once – so instead of {-ITEM} you must use {ITEM}

    [loop type=containers]
     [if field=title value='Container of Choice']
      [related acf_items]
        [set item][field title][/set]
      [/related]
      [pass vars]
       [-if var=item value='Item A']  
         This container only includes {ITEM}.
       [/-if]
       [-if var=item not value='Item A']  
         Other items not in this container are: {ITEM}.
        [/-if]
       [/pass]
     [/if]
    [/loop]

    If that does not work, try to pass the related field as list

    • This reply was modified 2 years, 10 months ago by polarracing.
    Thread Starter s1s2

    (@s1s2)

    I tried with {-ITEM} and {ITEM}, but I don’t seem to obtain the output for both items.

    Thread Starter s1s2

    (@s1s2)

    How can I pass the related output as a list? I’d love to do that, but I can’t figure out the syntax. Thanks!

    Pass the related field as list:

    [related acf_items]
        [set item][field title][/set]
      [/related]
      [pass vars]
       [-pass list='{ITEM}]
       [-if var=item value='Item A']  
         This container only includes {-ITEM}.
       [/-if]
       [-if var=item not value='Item A']  
         Other items not in this container are: {-ITEM}.
        [/-if]
       [/-pass]
       [/pass]
    • This reply was modified 2 years, 10 months ago by polarracing.
    Thread Starter s1s2

    (@s1s2)

    If you close the [related] tag before [pass], the list will be composed only of 1 item. I don’t understand why. Maybe I’m doing something wrong.

    To work with the whole list of items, you can do two things in my tests:

    1. run all code inside [related][/related], if possible.
    2. append each item that [related] outputs to a variable. Then you can pass that variable as a list in the way you have shown.

    Regardless, now I understand how to use a variable with [pass list=] and this has solved this issue and many other issues I had in other situations. Thank you!

    p.s.: in this specific situation, I wish I could have nested [related]. I tried [-related] but it doesn’t seem to work.

    I supposed CCS is amazing as is and I cannot ask for more.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Evaluate [related] fields’ is closed to new replies.