Skip to content

Instantly share code, notes, and snippets.

@leoken
Created October 27, 2013 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leoken/7188801 to your computer and use it in GitHub Desktop.
Save leoken/7188801 to your computer and use it in GitHub Desktop.
<?php
 
/*
* Get a field object and display it with it's value
*/
 
$field_name = "text_field";
$field = get_field_object($field_name);
 
echo $field['label'] . ': ' . $field['value'];
 
/*
* Get a field object and display it with it's value (using the field key and the value fron another post)
*/
 
$field_key = "field_5039a99716d1d";
$post_id = 123;
$field = get_field_object($field_key, $post_id);
 
echo $field['label'] . ': ' . $field['value'];
 
/*
* Get a field object and create a select form element
*/
 
$field_key = "field_5039a99716d1d";
$field = get_field_object($field_key);
 
if( $field )
{
echo '<select name="' . $field['key'] . '">';
foreach( $field['choices'] as $k => $v )
{
echo '<option value="' . $k . '">' . $v . '</option>';
}
echo '</select>';
}
 
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment