get_field_objects()

Description

Returns an array of custom field objects for a specific page / post.

This is a very simple function which finds ALL custom field values (that don’t start with an “_”) in the wp_postmeta table and returns them in an associated array where the $field_name => field object

You should only use this function when you do not know the fields which which will be appearing on a template or if you have a large amount of fields which you would prefer not to code independently.

Parameters

<?php $fields = get_field_objects($post_id); ?>
  • $post_id: Specific post ID where your value was entered. Defaults to current post ID (not required). This can also be options / taxonomies / users / etc

Usage

<?php

/*
*  get all custom fields and dump for testing
*/

$fields = get_field_objects();
var_dump( $fields ); 

/*
*  get all custom fields, loop through them and create a label => value markup
*/

$fields = get_field_objects();

if( $fields )
{
	foreach( $fields as $field_name => $field )
	{
		echo '<div>';
			echo '<h3>' . $field['label'] . '</h3>';
			echo $field['value'];
		echo '</div>';
	}
}

?>

Related

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.