Skip to content

Instantly share code, notes, and snippets.

@jakejackson1 jakejackson1/functions.php
Last active May 19, 2019

Embed
What would you like to do?
Convert Multi-Column List to Single Column
<?php
add_filter( 'gfpdf_pdf_field_content', function( $value, $field, $entry, $form, $pdf_field ) {
if ( $field->type === 'list' ) {
/* get out field value */
$value = $pdf_field->value();
$columns = is_array( $value[0] );
/* exit early if list field is empty */
if ( $pdf_field->is_empty() || ! $columns ) {
return '';
}
$columns = array_keys( $value[0] );
/* Start buffer and generate a list table */
ob_start();
?>
<table autosize="1" class="gfield_list">
<tbody class="contents">
<?php foreach ( $value as $item ) : ?>
<?php foreach ( $columns as $column ) : ?>
<tr>
<th>
<?php echo esc_html( $column ); ?>
</th>
</tr>
<tr>
<td>
<?php echo esc_html( rgar( $item, $column ) ); ?>
</td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
</tbody>
</table>
<?php
return ob_get_clean();
}
return $value;
}, 10, 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.