0

I am trying build my own wp_list_table. And i am using this following code: https://github.com/pmbaldha/WP-Custom-List-Table-With-Database-Example/blob/master/custom-list-table-db-example.php

It is works fine. But i want to add my custom fields. So i add this lines:

<?php 
    public function get_columns() {
        $columns = array(
            'cb'     => '<input type="checkbox" />',
            'name'   => __('Name', 'cltd_example'),
            'email'  => __('E-Mail', 'cltd_example'),
            'age'    => __('Age', 'cltd_example'),
            'custom' => __('Custom', 'cltd_example'), // Added this line
        );
        return $columns;
    }
?>

And:

<?php
function get_sortable_columns() {
    $sortable_columns = array(
        'name'   => array('name', true),
        'email'  => array('email', false),
        'age'    => array('age', false),
        'custom' => array('custom', false), // Added this line
    );
    return $sortable_columns;
}
?>

And

<?php
    $default = array(
        'id'     => 0,
        'name'   => '',
        'email'  => '',
        'age'    => null,
        'custom' => '', // Added this line
    );
?>

And added this into form:

<input id="custom" name="custom" type="text" style="width: 95%" value="<?php echo esc_attr($item['custom']); ?>" size="50" class="code" placeholder="<?php _e('Custom', 'cltd_example');?>" required>

But when i try to save new value, it says error. What is wrong?

  • 1
    There is no code responsible for save in the question. – Max Yudin Feb 28 '18 at 11:45
  • 1
    have you add your custom field in the database table? – Kanon Chowdhury Feb 28 '18 at 12:13
  • No :) but it add datatables with plugin activation. I am using it in theme function. I don't know how to add database fields in theme. – bilimokur Feb 28 '18 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.