Skip to content

Instantly share code, notes, and snippets.

@badcrocodile
Created July 11, 2013 01:22
Show Gist options
  • Save badcrocodile/5971756 to your computer and use it in GitHub Desktop.
Save badcrocodile/5971756 to your computer and use it in GitHub Desktop.
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>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment