Skip to content

Instantly share code, notes, and snippets.

@ddemuth
Created January 8, 2017 04:46
Show Gist options
  • Save ddemuth/4e483c2ef9e4f49c6bb4140e3070cce6 to your computer and use it in GitHub Desktop.
Save ddemuth/4e483c2ef9e4f49c6bb4140e3070cce6 to your computer and use it in GitHub Desktop.
add_action('wp_ajax_get_registrations_for_export', 'get_registrations_for_export');
add_action('wp_ajax_nopriv_get_registrations_for_export', 'get_registrations_for_export');
function get_registrations_for_export() {
// echo '<pre>';print_r($_GET);exit;
$post_statuses = array('unpaid', 'publish', 'cancelled');
$args = array(
'post_type' => 'fka_registrations',
'post_status' => $post_statuses,
'posts_per_page' => 25,
'no_found_rows' => true,
'fields' => 'ids'
);
$argsCount = array(
'post_type' => 'fka_registrations',
'post_status' => $post_statuses,
'posts_per_page' => -1,
'no_found_rows' => true,
'fields' => 'ids'
);
$registrations_to_export = get_posts( $args);
$registrations_count = get_posts( $argsCount);
$total_registrations = count($registrations_count);
//echo '<pre>';print_r($total_registrations);exit;
$registrations = array();
foreach ($registrations_to_export as $key => $registration_id) {
$class_activity = get_field('activity', $registration_id);
$activity_name = $class_activity->post_title;
$activity_id = $class_activity->ID;
$school_obj = get_field('school', $registration_id);
if ($school_obj) {
$school_name = $school_obj->post_title;
$school_id = $school_obj->ID;
}
$session_obj = get_field('session', $registration_id);
$session_name = $session_obj->name;
$session_id = $session_obj->term_id;
$product_info = get_page_by_title($school_name .' '. $activity_name, OBJECT, 'product');
if ($product_info) {
$fka_product_id = $product_info->ID;
}
$location = get_field('location_to_meet_coach', $fka_product_id);
$class_day = get_field('class_day', $fka_product_id);
$class_start_time = get_field('class_start_time', $fka_product_id);
$class_end_time = get_field('class_end_time', $fka_product_id);
$class_sessions = get_field('sessions', $fka_product_id);
$name = get_the_title($registration_id);
$array_key = fka_search_array($session_id, $class_sessions, $name);
// echo '<pre>';print_r($array_key);exit;
if ($array_key || $array_key == '0') {
$session_start_date = $class_sessions[$array_key]['session_start_date'];
$session_start_date = new DateTime($session_start_date);
$session_end_date = $class_sessions[$array_key]['session_end_date'];
$session_end_date = new DateTime($session_end_date);
}
$reg_post_status = get_post_status( $post);
if ($reg_post_status == 'publish') {
$reg_post_status = 'Paid';
}
$registrations[] = array(
$name,
$activity_name,
$school_name,
$class_day,
$class_start_time .' - '. $class_end_time,
$session_name,
$location,
'Test',
'English',
'hmmm',
'English',
'Dave',
'Demuth',
'Class',
'Test',
'English',
'Dave',
'Demuth',
'Class',
'Test',
'English'
);
}
$output['draw'] = 1;
$output['recordsTotal'] = $total_registrations;
$output['recordsFiltered'] = $total_registrations;
$output['data'] = $registrations;
wp_send_json($output);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment