Last active
August 29, 2015 14:15
-
-
Save JudeRosario/cda60d1f04d89b29eabd to your computer and use it in GitHub Desktop.
Fundraising Exports
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
# 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' |
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
$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 ; |
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
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) ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.