Created
January 5, 2017 23:41
-
-
Save ericnicolaas/4806c696b6e91a4b05beb90b2a4bd74d to your computer and use it in GitHub Desktop.
How to use the Charitable_Campaign object. See https://github.com/Charitable/Charitable/blob/master/includes/campaigns/class-charitable-campaign.php for the class definition.
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 | |
// Get a campaign object for the campaign with ID 123. | |
$campaign = charitable_get_campaign( 123 ); | |
// Get the campaign end date. | |
$end_date = $campaign->get_end_date(); | |
// Get the campaign end date, formatted like this: "9 January, 2017" | |
// You can use any valid PHP date format. See http://php.net/manual/en/function.date.php | |
$end_date = $campaign->get_end_date( 'j F, Y' ); | |
// Get the amount of time left in a campaign. | |
$time_left = $campaign->get_time_left(); | |
// Checks whether the campaign is endless (i.e. no expiry date). | |
$endless = $campaign->is_endless(); | |
// Checks whether the campaign has ended. | |
$ended = $campaign->has_ended(); | |
// Get the goal amount as a raw number. | |
$goal = $campaign->get_goal(); | |
// Get the goal amount formatted according to your currency settings. | |
$formatted_goal = $campaign->get_monetary_goal(); | |
// Checks if the campaign has a goal. | |
$has_goal = $campaign->has_goal(); | |
// Checks if the campaign has achieved its goal. | |
$has_achieved_goal = $campaign->has_achieved_goal(); | |
// Get the campaign status. | |
// This is NOT the same as the post_status. For published campaigns, | |
// the campaign will either be 'active' or 'finished', depending | |
// on whether it has ended. | |
$status = $campaign->get_status(); | |
// Get the amount donated to the campaign. | |
$amount = $campaign->get_donated_amount(); | |
// Get the amount donated as a formatted string. | |
// For campaigns with a goal, the format is like this: "$10 donated of $50 goal" | |
// For campaigns without a goal, the format is like this: "$10 donated" | |
$summary = $campaign->get_donation_summary(); | |
// Get the percentage raised. | |
// This gives you a formatted percentage like "55%". | |
$percent = $campaign->get_percent_donated(); | |
// Get the percentage raised as a raw amount. | |
$percent_raw = $campaign->get_percent_donated_raw(); | |
// Get the number of donors. | |
$donors = $campaign->get_donor_count(); | |
// Get the collection of donations as an array. | |
$donations = $campaign->get_donations(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment