Charitable Documentation

Learn how to make the most of Charitable with clear, step-by-step instructions.

Charitable_Campaign

The Charitable_Campaign class allows you to get information about a particular campaign.

Getting an instance of Charitable_Campaign

There are two primary ways to get a Charitable_Campaign object:

// Instantiate the object directly.
$campaign = new Charitable_Campaign( 123 );

// Get the object using a function.
$campaign = charitable_get_campaign( 123 );

While both options work, we recommend using charitable_get_campaign for forward-compatibility (in case we add object caching for campaigns or filtering).

Class source code

Methods

get( $meta_name, $single = true )

Get a value from the post_meta table.

This wraps around get_post_meta but automatically prepends _campaign_ to the meta field.

// These two are equivalent:
$end_date = $campaign->get( 'end_date', true );

$end_date = get_post_meta( $campaign->ID, '_campaign_end_date', true );

is_endless()

Returns whether a campaign is endless (i.e. it does not have an end date).

get_suggested_donations()

Returns an array containing the campaign’s suggested donation options.

If the campaign does not have any suggested donations, it will return an empty array.

get_end_date( $date_format = '' )

Returns the campaign end date, or false if the campaign does not have an end date.

Params
$date_format
If specified, sets the format for the end date. If you do not set a date format, the site’s date format will be used.

// Get the end date formatted according to the site's default date format.
$campaign->get_end_date();

// Get the end date formatted like "January 1, 2017"
$campaign->get_end_date( 'j F, Y' );

get_end_time()

Get the timestamp of the end date, or false if the campaign does not have an end date.

// Get the timestamp for the end date.
$campaign->get_end_time();

Still have questions? We’re here to help!

Last Modified: