• Resolved soulstatic

    (@soulstatic)


    Hey,
    I’m trying to add a single select field to the loop. Not sure how to do it.

    This is what I have. I know it’s wrong.

    (BTW, Great plugin!!)

    $fields = CFS()->get('resources');
    	                     foreach ($fields as $field) { ?>
    
     <?php .$values = CFS()->get('resource_type');
    foreach ($values as $value => $label) {
        echo '<td>' . $value . '</td>';
    }
    ?>
    	                     <?php echo '<td><a href="'.$field['resource_link'].'">'.$field['resource_title'].'</a></td></tr>'; ?>
    
    	                  <?php   }  ?>

    https://www.ads-software.com/plugins/custom-field-suite/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Matt Gibbs

    (@mgibbs189)

    Use var_dump on $fields to find out how the data is being stored. If “resources” is a loop, then all field values are within it. You don’t need separate get() calls.

    var_dump( $fields );
    Thread Starter soulstatic

    (@soulstatic)

    I’m not sure I follow. How would I call the field then?

    Thread Starter soulstatic

    (@soulstatic)

    OK. I just did the var_dump. Basically, I want to be able to echo array(1)

    Thread Starter soulstatic

    (@soulstatic)

    Hmm. I didn’t think this issue was resolved.

    Just posting the resolution here for anyone else who needs it.

    <?php
    /*
        A loop field named "gallery" with sub-fields "slide_title", "upload" and a select called file_type.
    */
    $fields = CFS()->get('gallery');
    foreach ($fields as $field) {
        echo $field['slide_title'];
        echo $field['upload'];
        echo current($field[file_type]);
    }
    ?>

    Since the select field “file_type” returns an array, using current will allow you to display the first item in the array.

    This solution only works for a select box where only one item can be chosen.

    Thanks @ mrspabs!
    Your solution worked for me!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Adding Select Field To the Loop’ is closed to new replies.