title: Wordpress Custom database table with DataTable server side processing
body: <p>I have followed <a href="https://itsmereal.com/datatables-server-side-processing-in-wordpress/" rel="nofollow noreferrer">this toturial</a> and have managed to create a shortcode that shows the datatable with filter option. This table works with the native post type of wordpress.</p>
  <p>I need the same datatable but it should get the data from a custom database table i have added <code>wp_lubuvna_subscribers</code></p>
  <p>Custom Table:
  <a href="https://i.stack.imgur.com/1MIqX.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1MIqX.jpg" alt="enter image description here" /></a></p>
  <p>So i need to change following function to get data from the above mentioned custom table instead custom post type</p>
  <pre><code>function datatables_server_side_callback_subscriber_db() {
   
      header(&quot;Content-Type: application/json&quot;);
   
      $request= $_GET;
   
      $columns = array(
          0   =&gt; 'post_title',
          3   =&gt; LUBUVNA_PREFIX.'email',
          1   =&gt; LUBUVNA_PREFIX.'first_name',
          2   =&gt; LUBUVNA_PREFIX.'last_name',
          4   =&gt; LUBUVNA_PREFIX.'phone'
          
      );
   
   
      $args = array(
          'post_type' =&gt; 'lubuvna_subscriber',
          'post_status' =&gt; 'publish',
          'posts_per_page' =&gt; $request['length'],
          'offset' =&gt; $request['start'],
          'order' =&gt; $request['order'][0]['dir'],
      );
   
      if ($request['order'][0]['column'] == 0) {
   
          $args['orderby'] = $columns[$request['order'][0]['column']];
   
      } elseif ($request['order'][0]['column'] == 1 || $request['order'][0]['column'] == 2) {
   
          $args['orderby'] = 'meta_value_num';
   
          $args['meta_key'] = $columns[$request['order'][0]['column']];
      }
   
      //$request['search']['value'] &lt;= Value from search
   
      if( !empty($request['search']['value']) ) { // When datatables search is used
          $args['meta_query'] = array(
              'relation' =&gt; 'OR',
              array(
                  'key' =&gt; 'd_title',
                  'value' =&gt; sanitize_text_field($request['search']['value']),
                  'compare' =&gt; 'LIKE'
              ),
              array(
                  'key' =&gt; LUBUVNA_PREFIX.'email',
                  'value' =&gt; sanitize_text_field($request['search']['value']),
                  'compare' =&gt; 'LIKE'
              ),
              array(
                  'key' =&gt; LUBUVNA_PREFIX.'first_name',
                  'value' =&gt; sanitize_text_field($request['search']['value']),
                  'compare' =&gt; 'LIKE'
              ),
              array(
                  'key' =&gt; LUBUVNA_PREFIX.'last_name',
                  'value' =&gt; sanitize_text_field($request['search']['value']),
                  'compare' =&gt; 'LIKE'
              ),
              array(
                  'key' =&gt; LUBUVNA_PREFIX.'phone',
                  'value' =&gt; sanitize_text_field($request['search']['value']),
                  'compare' =&gt; 'LIKE'
              ),
          );
      }
          
      $subscriber_query = new WP_Query($args);
      $totalData = $subscriber_query-&gt;found_posts;
   
      if ( $subscriber_query-&gt;have_posts() ) {
          
          while ( $subscriber_query-&gt;have_posts() ) {
           
              $subscriber_query-&gt;the_post();
   
              $nestedData = array();
              $nestedData[] = get_field(LUBUVNA_PREFIX.'first_name'). '&amp;nbsp'. get_field(LUBUVNA_PREFIX.'last_name');
              $nestedData[] = &quot;&lt;a data-val='&quot;.get_post_field( 'post_name', get_post() ).&quot;' href='&quot;.get_permalink().&quot;' data-posttype='&quot;.get_post_type( get_the_ID() ).&quot;' class='generallink'&gt;&quot; . get_field(LUBUVNA_PREFIX.'email') . &quot;&lt;/a&gt;&quot;;
              $nestedData[] = get_field(LUBUVNA_PREFIX.'first_name');
              $nestedData[] = get_field(LUBUVNA_PREFIX.'last_name');
              $nestedData[] = get_field(LUBUVNA_PREFIX.'phone');
   
              $data[] = $nestedData;
   
          }
   
          wp_reset_query();
   
          $json_data = array(
              &quot;draw&quot; =&gt; intval($request['draw']),
              &quot;recordsTotal&quot; =&gt; intval($totalData),
              &quot;recordsFiltered&quot; =&gt; intval($totalData),
              &quot;data&quot; =&gt; $data
          );
   
          echo json_encode($json_data);
   
      } else {
   
          $json_data = array(
              &quot;data&quot; =&gt; array()
          );
   
          echo json_encode($json_data);
      }
       
      wp_die();
   
  }
  </code></pre>