Home Forums Front-end Issues Absolute display of all fields


Absolute display of all fields

  • Hi,
    I’m trying to create a code that could display all fields, in an absolute way, without knowing the fields’names.
    But I’m stuck with my code when trying to get fields from a repeater field. From what I get, there’s no label at all for the fields inside a repeater. But it makes no sense. There should be.
    Here’s my attempt :

    $fields = get_field_objects();
    		if( $fields ):
    			echo '<div class="fields-container">';
    			foreach( $fields as $name => $field ):
    				$champ = get_field_object($name); // get the object by name
    				echo '<div class="' . $champ['name'] . '-label field-label">' . $champ['label'] . '</div>';
    				// if repeater
    				if( $champ['type'] == 'repeater' ) {
    					$rows = get_field_object($champ['name']);
    // here want an object with each row of the repeater to get the labels
    				// other fields
    				} else {
    					echo '<div class="' . $champ['name'] . '-value field-value">' . $champ['value'] . '</div>';
    			echo '</div>';

    I tried many things but never get the right object.
    Thanks a lot for any help.

  • Hi @vguenichon

    Here’s some code that I managed to get working to display details about the sub fields within a repeater:

    Note: I left my debugging statements intact, but commented out.

     // repeater field - this can be set dynamically within your loop of course... I set it statically for testing
      $field_obj = get_field_object( 'field_59dbae70e1416' );
      if ( $field_obj ) {
        if ( $field_obj['type'] == 'repeater' ) {
     // the array of sub fields within the repeater
          $sub_fields = $field_obj['sub_fields'];
          foreach( $sub_fields as $sub_field ) {
            echo '<p>key: ' . $sub_field['key'] . '<br />';
            echo 'label: ' . $sub_field['label'] . '<br />';
            echo 'name: ' . $sub_field['name'] . '</p>';
          //echo '<pre>';
          //echo '</pre>';
  • Fantastic ! I get the object.
    But… there’s no value at all in this object. Well the values are NULL in this new array and so when trying to ouptut $sub_field[‘value’]

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Absolute display of all fields’ is closed to new replies.