'count_post', //singular name of the listed records 'plural' => 'count_posts', //plural name of the listed records 'ajax' => false //does this table support ajax? ) ); } /** * Prepare the items for the table to process * * @return Void */ public function prepare_items($post_type) { global $wpdb; //This is used only if making any database queries /** * First, lets decide how many records per page to show */ $per_page = -1; /** * REQUIRED. Now we need to define our column headers. This includes a complete * array of columns to be displayed (slugs & titles), a list of columns * to keep hidden, and a list of columns that are sortable. Each of these * can be defined in another method (as we've done here) before being * used to build the value for our _column_headers property. */ $columns = $this->get_columns(); $hidden = array(); $sortable = $this->get_sortable_columns(); /** * REQUIRED. Finally, we build an array to be used by the class for column * headers. The $this->_column_headers property takes an array which contains * 3 other arrays. One for all columns, one for hidden columns, and one * for sortable columns. */ $this->_column_headers = array($columns, $hidden, $sortable); /** * Optional. You can handle your bulk actions however you see fit. In this * case, we'll handle them within our package just to keep things clean. */ //$this->process_bulk_action(); /** * Instead of querying a database, we're going to fetch the example data * property we created for use in this plugin. This makes this example * package slightly different than one you might build on your own. In * this example, we'll be using array manipulation to sort and paginate * our data. In a real-world implementation, you will probably want to * use sort and pagination data to build a custom query instead, as you'll * be able to use your precisely-queried data immediately. */ $data = $this->table_data($post_type); /** * This checks for sorting input and sorts the data in our array accordingly. * * In a real-world situation involving a database, you would probably want * to handle sorting by passing the 'orderby' and 'order' values directly * to a custom query. The returned data will be pre-sorted, and this array * sorting technique would be unnecessary. */ /*********************************************************************** * --------------------------------------------------------------------- * vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv * * In a real-world situation, this is where you would place your query. * * For information on making queries in WordPress, see this Codex entry: * http://codex.wordpress.org/Class_Reference/wpdb * * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ * --------------------------------------------------------------------- **********************************************************************/ /** * REQUIRED for pagination. Let's figure out what page the user is currently * looking at. We'll need this later, so you should always include it in * your own package classes. */ $current_page = $this->get_pagenum(); /** * REQUIRED for pagination. Let's check how many items are in our data array. * In real-world use, this would be the total number of items in your database, * without filtering. We'll need this later, so you should always include it * in your own package classes. */ $total_items = count($data); /** * The WP_List_Table class does not handle pagination for us, so we need * to ensure that the data is trimmed to only the current page. We can use * array_slice() to */ $data = array_slice($data,(($current_page-1)*$per_page),$per_page); /** * REQUIRED. Now we can add our *sorted* data to the items property, where * it can be used by the rest of the class. */ $this->items = $data; /** * REQUIRED. We also have to register our pagination options & calculations. */ $this->set_pagination_args( array( 'total_items' => $total_items, //WE have to calculate the total number of items 'per_page' => $per_page, //WE have to determine how many items to show on a page 'total_pages' => ceil($total_items/$per_page) //WE have to calculate the total number of pages ) ); } /** * Override the parent columns method. Defines the columns to use in your listing table * * @return Array */ public function get_columns() { $columns = array( // 'cb' => '', //Render a checkbox instead of text 'title' => 'Title', 'author' => 'Author', 'date' => 'Date' ); return $columns; } /** * Get the table data * * @return Array */ private function table_data($post_type) { $data = array(); global $post; $author_id=intval($_GET['user_id']); $page_post= new WP_Query( array('post_type'=>$post_type,'posts_per_page'=>-1,'author'=>$author_id,'post_status'=>'any') ); while($page_post->have_posts()):$page_post->the_post(); $data[] = array( 'title' => ''.get_the_title().'', 'author' => get_the_author(), 'post_type' => $post_type, 'date' => $post->post_date, 'id' => $post->ID, ); endwhile; wp_reset_postdata(); return $data; } /** * Define what data to show on each column of the table */ public function column_default( $item, $column_name ) { switch($column_name){ case 'author': case 'date': return $item[$column_name]; default: return print_r($item,true); //Show the whole array for troubleshooting purposes } } /* title*/ function column_title($item){ do_action( 'quick_edit_custom_box', $column_name, 'edit-tags', $tax->name ); //Return the title contents return sprintf('%1$s %3$s', /*$1%s*/ $item['title'], /*$2%s*/ $item['ID'], /*$3%s*/ $this->row_actions($actions) ); } } ?>