Created
January 17, 2021 03:55
-
-
Save gvgvgvijayan/be44c43a1f59db909ab7afc9c0de8086 to your computer and use it in GitHub Desktop.
This gist is used in the tutorial https://www.vijayan.in/how-to-create-custom-table-list-in-wordpress-admin-page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
... | |
/** | |
* Prepare the data for the WP List Table | |
* | |
* @return void | |
*/ | |
public function prepare_items() { | |
$columns = $this->get_columns(); | |
$sortable = $this->get_sortable_columns(); | |
$hidden = array(); | |
$primary = 'title'; | |
$this->_column_headers = array( $columns, $hidden, $sortable, $primary ); | |
$data = array(); | |
$this->process_bulk_action(); | |
$get_posts_obj = $this->get_posts_object(); | |
if ( $get_posts_obj->have_posts() ) { | |
while ( $get_posts_obj->have_posts() ) { | |
$get_posts_obj->the_post(); | |
$data[ get_the_ID() ] = array( | |
'id' => get_the_ID(), | |
'title' => get_the_title(), | |
'type' => ucwords( get_post_type_object( get_post_type() )->labels->singular_name ), | |
'date' => get_post_datetime(), | |
'author' => get_the_author(), | |
); | |
} | |
wp_reset_postdata(); | |
} | |
$this->items = $data; | |
$this->set_pagination_args( | |
array( | |
'total_items' => $get_posts_obj->found_posts, | |
'per_page' => $get_posts_obj->post_count, | |
'total_pages' => $get_posts_obj->max_num_pages, | |
) | |
); | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment