Site icon Hip-Hop Website Design and Development

WP_list_table prepare_items()

I create customized WP_list_table with facet type like (including new class type), however when i submit that type wp_list_table would not refresh. After I as soon as once more refresh web page info seems.I take advantage of wp_list_table_example plugin the whole lot is similar apart from geting example_data and type.

 class TT_Example_List_Table extends WP_List_Table {

    operate __construct(){
        world $standing, $web page;

        //Set dad or mum defaults
        dad or mum::__construct( array(
            'singular'  => 'film',     //singular identify of the listed information
            'plural'    => 'motion pictures',    //plural identify of the listed information
            'ajax'      => false        //does this desk assist ajax?
        ) );

    }
    operate column_default($merchandise, $column_name){
        swap($column_name){
            case 'score':
            case 'director':
                return $merchandise[$column_name];
            default:
                return print_r($merchandise,true); //Present the entire array for troubleshooting functions
        }
    }

    operate column_title($merchandise){

        //Construct row actions
        $actions = array(
            'edit'      => sprintf('<a href="?web page=%s&motion=%s&film=%s">Edit</a>',$_REQUEST['page'],'edit',$merchandise['ID']),
            'delete'    => sprintf('<a href="?web page=%s&motion=%s&film=%s">Delete</a>',$_REQUEST['page'],'delete',$merchandise['ID']),
        );

        //Return the title contents
        return sprintf('%1$s <span model="shade:silver">(id:%2$s)</span>%3$s',
            /*$1percents*/ $merchandise['title'],
            /*$2percents*/ $merchandise['ID'],
            /*$3percents*/ $this->row_actions($actions)
        );
    }
    operate column_cb($merchandise){
        return sprintf(
            '<enter sort="checkbox" identify="%1$s[]" worth="%2$s" />',
            /*$1percents*/ $this->_args['singular'],  //Let's merely repurpose the desk's singular label ("film")
            /*$2percents*/ $merchandise['ID']                //The worth of the checkbox ought to be the report's id
        );
    }

    operate get_columns(){
        $columns = array(
            'cb'        => '<enter sort="checkbox" />', //Render a checkbox as a substitute of textual content
            'title'     => 'Title',
            'score'    => 'Score',
        );
        return $columns;
    }

    operate get_sortable_columns() {
        $sortable_columns = array(
            'title'     => array('title',false),     //true means it is already sorted
            'score'    => array('score',false),
            'director'  => array('director',false)
        );
        return $sortable_columns;
    }

    operate get_bulk_actions() {
        $actions = array(
            'delete'    => 'Delete'
        );
        return $actions;
    }
    operate process_bulk_action() {

        //Detect when a bulk motion is being triggered...
        if( 'delete'===$this->current_action() ) {
            wp_die('Gadgets deleted (or they'd be if we had objects to delete)!');
        }

    }
    operate prepare_items() {


          $knowledge = array();
        $example_data = array();
    $phrases = get_terms( 'productcat', array('hide_empty' => false));

print_r($phrases);
        if ( ! empty( $phrases )  ){
     foreach ( $phrases as $time period ) {

         $knowledge[] = array(
                            'ID'          =>  $term->term_id,
                            'title'       => $term->identify
                            );

     }
 }

        $example_data = $knowledge;

        $per_page = 5;


        $columns = $this->get_columns();
        $hidden = array();
        $sortable = $this->get_sortable_columns();
        $this->_column_headers = array($columns, $hidden, $sortable);
        $this->process_bulk_action();
        $knowledge = $example_data;

        operate usort_reorder($a,$b){
            $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'title'; //If no type, default to title
            $order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'asc'; //If no order, default to asc
            $outcome = strcmp($a[$orderby], $b[$orderby]); //Decide type order
            return ($order==='asc') ? $outcome : -$outcome; //Ship closing type route to usort
        }
        usort($knowledge, 'usort_reorder');

        $current_page = $this->get_pagenum();
        $total_items = depend($knowledge);
        $knowledge = array_slice($knowledge,(($current_page-1)*$per_page),$per_page);

        $this->objects = $knowledge;


        $this->set_pagination_args( array(
            'total_items' => $total_items,                  //WE need to calculate the whole variety of objects
            'per_page'    => $per_page,                     //WE have to find out what number of objects to point out on a web page
            'total_pages' => ceil($total_items/$per_page)   //WE need to calculate the whole variety of pages
        ) );
    }


}


operate tt_add_menu_items(){
    add_menu_page('Instance Plugin Record Desk', 'Record Desk Instance', 'activate_plugins', 'tt_list_test', 'tt_render_list_page');
} add_action('admin_menu', 'tt_add_menu_items');


operate tt_render_list_page(){

    //Create an occasion of our bundle class...
    $testListTable = new TT_Example_List_Table();
    //Fetch, put together, type, and filter our knowledge...
    $testListTable->prepare_items();




    ?>
    <div class="wrap">

        <div id="icon-users" class="icon32"><br/></div>
        <h2>Record Desk Check</h2>

        <type id="movies-filter" methodology="GET">

            <!-- For plugins, we additionally want to make sure that the shape posts again to our present web page -->
            <enter sort="hidden" identify="web page" worth="<?php echo $_REQUEST['page'] ?>" />
            <!-- Now we are able to render the finished record desk -->
            <?php $testListTable->show(); ?>

        </type>
          <type id="insert_term" identify="insert_term" methodology="publish" motion=""> 

           <div class="form-field  term-name-wrap">
          <label for="time period">Time period</label>
         <enter sort="textual content" worth="" identify="time period" id="time period" measurement="40" />
         <p>Description</p>
        </div>

    <label>Description</label><enter sort="textual content" worth="" identify="termdesc" id="termdesc" />

    <enter sort="submit" worth="Add time period" id="submit" identify="submit" />
    <enter sort="hidden" identify="motion" worth="new_term" />

</type> 

         <?php

if( 'POST' == $_SERVER['REQUEST_METHOD']) &&  $_POST['action'] == "new_term") {
if (isset($_POST['term']) && !empty( $_POST['term']) ) {

 $new_term =  $_POST['term'];
 $description = $_POST['desc'];
        wp_insert_term(
          $new_term,
          'productcat',
            array(
         'description'=> $description,
        ));

    } 

}

?>        
    </div>
    <?php
}

My query is, after I add within the type new time period why not refresh wp_list_table, is it due to the best way of getting knowledge or the best way knowledge is added.
How refresh wp_table_list after i submit new time period. Any assistance is welcome.