Skip to content

Instantly share code, notes, and snippets.

@bryanmonzon
Created February 21, 2015 00:34
Show Gist options
  • Save bryanmonzon/49ea6b0eda2205667fcf to your computer and use it in GitHub Desktop.
Save bryanmonzon/49ea6b0eda2205667fcf to your computer and use it in GitHub Desktop.
Sample code for getting and returning campaign post meta.
<?php
/**
* Assuming we're on the Campaign Single template
* this is what it would look like to access and show
* campaign data.
*
* Note: This is just a sample template.
*/
get_header();
/**
* Since we're on the single template we have access to the $post object, automatically. Otherwise, this will need to go in the loop.
*
* We'll use get_post_meta(); to access data stored in the campaign.
*/
$dntly_data = get_post_meta( $post->ID, '_dntly_data', true ); //This will set $donately_data to an array (this will change in the next major release).
//Below we're using ternary operators to check is the array key/value isset. If it's not, we set it to zero to prevent PHP warnings.
$campaign_goal = (isset($dntly_data['campaign_goal']) ? intval($dntly_data['campaign_goal']) : 0 );
$donations_count = (isset($dntly_data['donations_count']) ? intval($dntly_data['donations_count']) : 0 );
$donors_count = (isset($dntly_data['donors_count']) ? intval($dntly_data['donors_count']) : 0 );
$amount_raised = (isset($dntly_data['amount_raised']) ? intval($dntly_data['amount_raised']) : 0 );
$percent_funded = (isset($dntly_data['percent_funded']) ? $dntly_data['percent_funded'] : 0 );
?>
<div class="content">
<?php if( have_posts() ) : while( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<div class="donately-data">
<span class="campagin-goal">Goal: <?php echo $campaign_goal; ?></span>
<span class="amount-raised">Goal: <?php echo $amount_raised; ?></span>
</div>
<?php endwhile; endif; ?>
</div>
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment