badcrocodile
7/11/2013 - 1:22 AM

Dumps all custom fields attached to given page ID.

Dumps all custom fields attached to given page ID.

<?php
$custom_fields = get_post_custom(985);

// Prints out all custom field names and values
echo "<p style='line-height:2em;'>";
/*
 * We only want our special ACF's, 
 * so lets set up a string comparison
 */ 
$findMe = 'gcfx_'; // Notice the naming convention!! All fields you want to use here need this. Should make it into a variable.
foreach ( $custom_fields as $key => $value ) { // $custom_fields is a multidimensional array 
  foreach ( $value as $newkey => $newvalue ) { // so we need to foreach it twice
		$pos = strpos( $key, $findMe ); // sift through all ACF's, returning only the ones containing our substring
		if ( ( $pos !== false ) && ( $pos == 0 ) ) { // ACF essentally doubles all CF's it creates by prefacing them with a "_". To filter those out we need to do an additional "&&". 
			echo "$key has a value of $newvalue <br />"; // Woot! We now have the name and value of all of our ACF's! Booyah.
		}
	}
}
 echo "</p>";
?>