get_fields()

Overview

Returns an array of values (name => value) for a specific post.

Parameters

get_fields([$post_id]);
  • $post_id (mixed) (Optional) The post ID where the values are saved. Defaults to the current post

Usage

Output all fields

This example shows how to display all fields (name and value) in a list.

<?php 

$fields = get_fields();

if( $fields ): ?>
	<ul>
		<?php foreach( $fields as $name => $value ): ?>
			<li><b><?php echo $name; ?></b> <?php echo $value; ?></li>
		<?php endforeach; ?>
	</ul>
<?php endif; ?>

Debug

This example shows how the get_fields() function can be used to debug the available values for the post = 123.

<?php 

echo '<pre>';
	print_r( get_fields(123) );
echo '</pre>';

?>

Related