<?php
add_action( 'wp_ajax_getpostsfordatatables', 'my_ajax_getpostsfordatatables' );
add_action( 'wp_ajax_nopriv_getpostsfordatatables', 'my_ajax_getpostsfordatatables' );
function my_ajax_getpostsfordatatables() {
  /*global $wpdb;
  //some basic query arguments
  $posts_per_page = 3;
  $page = 1;
  $args = array(
    'post_type'             => 'sfwd-courses',
    'posts_per_page'        => $posts_per_page,
    'paged'                 => $page
  );
  //query
  $postsQ = new WP_Query( $args );
 

//print_r($postsQ);

  //create empty array and loop through results, populating array
  $return_json = array();
  while($postsQ->have_posts()) {
    $postsQ->the_post();
    $row = array(
      'id' => get_the_ID(),
      'title' => get_the_title(),
      'author' => get_the_author(),
      'date' => get_the_date('Y-m-d'),
      'excerpt' => strip_tags(get_the_excerpt()),
      'link' => get_permalink()
    );
    $return_json[] = $row;
  }
  //return the result to the ajax request and die
  echo json_encode(array('data' => $return_json));
  */


/*$users = get_users( array( 'fields' => array( 'ID' ) ) );
foreach($users as $user){
    
$row = array(
    'id' => $user->ID,
    $userinfo = get_user_meta($user->ID);
    'Student Name'=> $userinfo['first_name'][0].' '.$userinfo['last_name'][0],
    $couse_info = unserialize($userinfo['_sfwd-course_progress'][0]);
    foreach ($couse_info as $key => $value) {
    'Course' => $key,
    'Date Completed' => '',
      $quiz = unserialize($userinfo['_sfwd-quizzes'][0]);
      if($quiz[0]['course'] == $key){
      'Course Grade' => $quiz[0]['percentage'],
      } //endif
    }// foreach

    'Report Grade' => 'Send'
);
 $return_json[] = $row;

}//foreach
echo json_encode(array('data' => $return_json));
*/
  wp_die();
}