Skip to content

Instantly share code, notes, and snippets.

@dontfeedthecode
Created July 15, 2012 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dontfeedthecode/3116352 to your computer and use it in GitHub Desktop.
Save dontfeedthecode/3116352 to your computer and use it in GitHub Desktop.
Easily accessing all Pod fields in Pods Framework for WordPress
<?php
// Example for use in one of your custom pod theme templates
global $pods;
$website = new Pod('websites', 'my-website');
if( !empty( $website->data ) )
{
// Pass Pod ID to function and retrieve array of fields
foreach(getPodFields($website->get_field('id')) as $field)
// Prepend with Pod name to avoid pollution
${'website_'.$field} = $website->get_field($field);
}
// Now you can use these new variables throughout your template
// without needing to run get_field() over and over again - Huzzah!
?>
<h1><?php echo $website_name; ?></h1>
<p><?php echo $website_description; ?></p>
<img src="<?php echo $website_thumbnail[0]['guid']; ?>" alt="" />
<?php
function getPodFields($pod_id)
{
// Initiate Pods API
$api = new PodAPI();
// Load Pod via ID
$pod = $api->load_pod(array('id' => $pod_id));
// Add fields to array
foreach($pod['fields'] as $k => $v) $fields[] = $k;
// Return array of Pod fields
return $fields;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment