Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.9 kB
2
Indexable
Never
///// CODE I CANNOT GET TO WORK ///
** ASSUME I INCLUDED ALL THE EDITOR FILES NECESSARY

var editor = new $.fn.dataTable.Editor( {
	ajax: "https://website.com/wp-content/themes/theme-Child/Editor/controllers/users.php", // THIS IS A MODIFIED
	type: "POST",
	// "ajax": ajax_url,
	table: "#adminreport",
});

IT SEEMS THAT USERS.PHP IS NOT EVEN BEING EXECUTED BECAUSE I GET THE FULL TABLE AS JSON RESULTS RATHER THAN SOME SEARCH RESULTS FROM THE SEARCH BUILDER. AND I TRIED ABSOLUTE AND RELATIVE LINKING TO THE USERS.PHP FILE NO SUCCESS


//////// EVERTHING BELOW IS WORKING ///////////

///////// JAVASCRIPT /////////

 .DataTable({
		"processing": true,
		"serverSide": true,
		"ajax": ajax_url,
		"pageLength": 70,
		"search": {
		  "return": true
		}
});



//////// PHP //////////

add_action('wp_ajax_fc_datatables', 'datatables_server_side_callback');
add_action('wp_ajax_nopriv_fc_datatables', 'datatables_server_side_callback');


function datatables_server_side_callback() {

    header("Content-Type: application/json");


    $args = array(

    'orderby' => 'display_name', 
    'order' => 'ASC',
    'role__in'    => array(
        '10_'.$dates['programme_year'].'_active'
    ),
    'number' => 70,
    'offset' => $request['start'],
    'order' => $request['order'][0]['dir'],
    );


    $movie_query = new WP_User_Query($args);
    $totalData = $movie_query->get_total();

    if ( ! empty( $movie_query->get_results() ) ) {
        foreach ( $movie_query->get_results() as $user ) {

        $nestedData = array();        
        $nestedData[] = $user->display_name;

        $data[] = $nestedData;

    }

    wp_reset_query();

    $json_data = array(
      "draw" => intval($request['draw']),
      "recordsTotal" => intval($totalData),
      "recordsFiltered" => intval($totalData),
      "data" => $data
    );

    echo json_encode($json_data);
}
Leave a Comment