get_row()ACF 1.0

Gets an array (in name => value format) for the current row of a have_rows() loop.

Comparison with the_row()

The function returns the same data as the_row(), but it does not include row processing in the have_rows() loop.

No Hooks.

Returns

null. An array in name => value format.

Usage

get_row( $format_value );
$format_value(true/false)
Apply formatting logic.
Default: true

Examples

#1 Load and display the current row values

<?php if( have_rows('slides') ): ?>

	<?php
	while( have_rows('slides') ): the_row();

		// Get all values for this row.
		$row = get_row();

		// Check for image value.
		if( $row['image'] ){
			?>
			<img src="<?php echo $row['image']; ?>" />
			<p><?php echo $row['caption']; ?></p>
			<?php
		}
		?>

	<?php endwhile; ?>

<?php endif; ?>

get_row() code ACF 6.8.8

function get_row( $format = false ) {

	// vars
	$loop = acf_get_loop( 'active' );

	// bail early if no loop
	if ( ! $loop ) {
		return false;
	}

	// get value
	$value = acf_maybe_get( $loop['value'], $loop['i'] );

	// bail early if no current value
	// possible if get_row_layout() is called before the_row()
	if ( ! $value ) {
		return false;
	}

	// format
	if ( $format ) {

		// vars
		$field = $loop['field'];

		// single row
		if ( acf_get_field_type_prop( $field['type'], 'have_rows' ) === 'single' ) {

			// format value
			$value = acf_format_value( $value, $loop['post_id'], $field );

			// multiple rows
		} else {

			// format entire value
			// - solves problem where cached value is incomplete
			// - no performance issues here thanks to cache
			$value = acf_format_value( $loop['value'], $loop['post_id'], $field );
			$value = acf_maybe_get( $value, $loop['i'] );
		}
	}

	// return
	return $value;
}