Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fundraising Exports
# You can pull additional data in the SELECT if needed
SELECT post_name, post_date, post_author,
post_status, post_parent, meta_value
# Both tables contain all the data you'll ever need with the plugin
FROM wp_posts
INNER JOIN wp_postmeta
ON wp_posts.ID = wp_postmeta.post_id
# You can set this to funder if you want to pull details on funds
WHERE wp_posts.post_type = 'donation'
AND wp_postmeta.meta_key = 'wdf_transaction'
$pledges = $wpdb->get_results($query) ;
// Loop through each Pledge
foreach($pledges as $pledge) :
// A unique String for the pledge.
// Alternatively you can use post ID
$pledge_unique_ID = $pledge->post_name;
// Date a pledge was made
// You can add modified date for reccuring pledges
$pledge_date = $pledge->post_date ;
// All details you need about the backers are stored in this variable
$backer= get_userdata( $pledge->post_author ) ;
$backer_name=$backer->user_nicename;
$backer_email=$backer->user_email;
// Status of the pleding in the system
$pledge_status = $pledge->post_status;
// The Title of the Fundraiser, for which this pledge was made
$fundraiser = get_the_title( $pledge->post_parent ) ;
// Unserialiize the Transaction Log and extract data from it
$transaction = unserialize( $pledge->meta_value );
$pledge_amount = $transaction['gross'] ;
$pledge_type = $transaction['type'] ;
$pledge_currency = $transaction['currency_code'] ;
$pledge_gateway = $transaction['gateway_public'] ;
$pledge_gateway_status_message = $transaction['gateway_msg'] ;
endforeach ;
global $wpdb ;
$query = " SELECT post_name, post_date, post_author,
post_status, post_parent, meta_value
FROM wp_posts
INNER JOIN wp_postmeta
ON wp_posts.ID = wp_postmeta.post_id
WHERE wp_posts.post_type = 'donation'
AND wp_postmeta.meta_key = 'wdf_transaction' " ;
$pledges = $wpdb->get_results($query) ;
// A file handle
$export_file = fopen("pledges.csv","w") ;
foreach($pledges as $pledge) :
// A unique String for the pledge.
// Alternatively you can use post ID
$pledge_unique_ID = $pledge->post_name;
// The Title of the Fundraiser, for which this pledge was made
$fundraiser = get_the_title( $pledge->post_parent ) ;
// Date a pledge was made
// You can add modified date for reccuring pledges
$pledge_date = $pledge->post_date ;
// All details you need about the backers are stored in this variable
$backer= get_userdata( $pledge->post_author ) ;
$backer_name=$backer->user_nicename;
$backer_email=$backer->user_email;
// Status of the pleding in the system
$pledge_status = $pledge->post_status;
// Unserialiize the Transaction Log and extract data from it
$transaction = unserialize( $pledge->meta_value );
$pledge_amount = $transaction['gross'] ;
$pledge_type = $transaction['type'] ;
$pledge_currency = $transaction['currency_code'] ;
$pledge_gateway = $transaction['gateway_public'] ;
$pledge_gateway_status_message = $transaction['gateway_msg'] ;
// Write it into the CSV file
fputcsv($export_file,
array(
$pledge_unique_ID,
$fundraiser,
$pledge_date,
$backer_name,
$backer_email,
$pledge_status,
$pledge_amount,
$pledge_type,
$pledge_currency,
$pledge_gateway,
$pledge_gateway_status_message
));
endforeach ;
// IMPORTANT : Close file handle so you can safely use file elsewhere
fclose($export_file) ;
@JudeRosario

This comment has been minimized.

Copy link
Owner Author

commented Feb 13, 2015

Simply put this file into a function and trigger it for the CSV export. Also replace the path to the out file with your own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.