Created
July 15, 2012 11:34
-
-
Save dontfeedthecode/3116352 to your computer and use it in GitHub Desktop.
Easily accessing all Pod fields in Pods Framework for WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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="" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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