Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Eliot Akira

    (@miyarakira)

    Currently, there’s no general way to loop through an array in a field.

    However, there is already looping with arrays, for example, in attachments, gallery field, field types in ACF, metabox in WCK, etc., so I imagine it’s possible to implement it somehow.

    Is this array saved as a simple list [1,2,3] or with key value pairs?

    Thread Starter Steve

    (@stevesicherman)

    Saved as key value pairs. If you could loop through an array in the same manner as the existing [repeater] syntax that’d be a slick addition.

    Plugin Author Eliot Akira

    (@miyarakira)

    OK, I’ll look into it and let you know when I’ve got something.

    Thread Starter Steve

    (@stevesicherman)

    That’d be great!

    Plugin Author Eliot Akira

    (@miyarakira)

    Another question: do you know the specific keys in this array? For example, I’m imagining something like this:

    [field-array field_name]
      [field key_name1]
      [field key_name2]
    [/field-array]

    Would that work?

    Thread Starter Steve

    (@stevesicherman)

    That would be perfect!

    Plugin Author Eliot Akira

    (@miyarakira)

    OK, please see the latest update. I simplified it to:

    [array field_name]
      [field key_1]
      [field key_2]
    [/array]

    Hmm, looking at this, I realized it’s not really a “loop” since it goes through only once. I hope that’s what you needed!

    Thread Starter Steve

    (@stevesicherman)

    Hmm I’m not seeing any result (I downloaded the latest update).

    Perhaps a screenshot of the array would help:
    https://i.imgur.com/4I0ALBT.gif

    From this array I would expect this code:

    [loop type='location']
    [array socialicons]
      [field socialicons_network]<br>
    [/array]
    [/loop]

    to produce:

    facebook
    twitter
    google-plus

    Plugin Author Eliot Akira

    (@miyarakira)

    Hmm..looks like you have a field that’s structured like this:

    Array
    (
        [0] => Array
            (
                [social_icons_url] => '/'
                [social_icons_network] => 'facebook'
                [social_icons_flyoutcontent] => 'etc.'
            )
        [1] => Array..
        [2] => Array..

    ..whereas currently [array] expects something simpler, like:

    Array
    (
        [key_1] => value_1
        [key_2] => value_2
    )

    Yeah..I was afraid that a shortcode to parse arrays can get complicated, since there are many different ways data can be stored in a field.

    OK, I’ll add a parameter that will loop through each array in the field.

    Plugin Author Eliot Akira

    (@miyarakira)

    So, please try the latest update with:

    [loop type="location"]
      [array socialicons each="true"]
        [field socialicons_network]<br>
      [/array]
    [/loop]

    That should loop through each array.

    Thread Starter Steve

    (@stevesicherman)

    That works great, thank you!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Arrays in fields’ is closed to new replies.