• I have a custom post type called Vehicles. For it, I defined an ACF field called “acf_type” which presents a selection among multiple choices: bike, car, etc.

    I’d like to show some identical HTML for each one of these types, grouping them one after the other in the same page. For example:

    <div class="title">Bike</div>
    <div class="description">something something</div>
    
    <div class="title">Car</div>
    <div class="description">something something</div>

    To achieve this, I tried the following:

    [loop type=vehicles orderby=name]
     [for each=acf_type]
       <div class="title">[field acf_type]</div>
       <div class="description">[field acf_description]</div>
     [/for]
    [/loop]

    but I obtain nothing. I either misunderstand the purpose of “for each”, or I’m doing some mistakes with the syntax.

    Any help would be greatly appreciated.

Viewing 1 replies (of 1 total)
  • The [for each] shortcode is only for taxonomy terms, not for field values. If you want to “loop” through all existing “types” on your website (or the terms assigned to one post) you may consider using a taxonomy and add the description to the description field of the term.

    To loop through a list of values in a field of one “post”, there is the [pass field_loop=serial_numbers] shortcode, but I think it’s not working for your user case.

    Peter

Viewing 1 replies (of 1 total)
  • The topic ‘Troubles with “for each”’ is closed to new replies.